-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtodosApi.js
executable file
·45 lines (43 loc) · 1003 Bytes
/
todosApi.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* eslint-disable no-unused-vars */
import env from '../config/envConfig'
import fetch from 'isomorphic-unfetch'
class TodosApi {
static getTodos () {
return new Promise((resolve, reject) => {
fetch(`${env.BACKEND_URL}/todos`, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
})
.then(r => r.json())
.then(res => {
resolve(res.todos)
})
.catch(e => {
reject(e)
})
})
}
static getJokes (access) {
return new Promise((resolve, reject) => {
fetch(`${env.BACKEND_URL}/BACKEND_URL/jokes/celebrity`, {
method: 'GET',
headers: {
Authorization: `Bearer ${access.token}`
}
})
.then(r => {
const result = r.json()
return result
})
.then(res => {
resolve({ jokes: res })
})
.catch(e => {
reject(e)
})
})
}
}
export default TodosApi