forked from benmvp/react-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (37 loc) · 1.04 KB
/
index.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
import 'whatwg-fetch';
export const addEmail = (email) => (
// Make a JSON POST with the new email
fetch('//localhost:9090/emails', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(email)
})
.then((res) => res.json())
);
export const deleteEmail = (emailId) => (
// Make a DELETE request
fetch(`//localhost:9090/emails/${emailId}`, {
method: 'DELETE'
})
.then((res) => res.json())
);
export const getEmails = () => (
// Make a GET request
fetch('//localhost:9090/emails')
.then((res) => res.json())
);
export const setUnread = (emailId, unread=true) => (
// Make a PUT request to update unread state
fetch(`//localhost:9090/emails/${emailId}`, {
method: 'PUT',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({unread})
})
.then((res) => res.json())
);