fetch url options const headers Accept application json Content-Type a

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
fetch = (url, options) => {
const headers = {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
if (this.authorized()) {
headers['Authorization'] = 'Bearer ' + this.getToken()
}
return fetch(url, {
headers,
...options
});
}
fetchJson = async (url, options) => {
let response = await this.fetch(url, options);
let json = await response.json();
return json;
}