Files
airjet/webapp/scripts/fetcher.js
2023-05-10 20:43:45 +02:00

58 lines
1.2 KiB
JavaScript

async function get(url, token) {
const response = await fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
authorization: `${token}`
},
});
const data = await response.json();
return { status: response.status, data: data };
}
async function post(url, json, token) {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
authorization: `${token}`
},
body: JSON.stringify(json),
});
const data = await response.json();
return { status: response.status, data: data };
}
async function patch(url, json, token) {
const response = await fetch(url, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
authorization: `${token}`
},
body: JSON.stringify(json),
});
const data = await response.json();
return { status: response.status, data: data };
}
async function put(url, json, token) {
const response = await fetch(url, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
authorization: `${token}`
},
body: JSON.stringify(json),
});
const data = await response.json();
return { status: response.status, data: data };
}