blob: 0381f1852b571c3119b150094c09c2c5c650c9d4 (
plain)
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
|
/**
* Accept an API endpoint, method, and body to send to the API.
* - If successful, return the response
* - If not, return false
* @param {*} endpoint API endpoint
* @param {*} method String (GET, POST, PUT, DELETE)
* @param {*} body Data to send to the API
* @returns response.json or false
*/
async function accessAPI(endpoint, method, body) {
let response = await fetch(`http://127.0.0.1:5252/api${endpoint}`, {
method: method,
credentials: 'include',
body: body,
});
if (response.ok) {
let data = await response.json();
data = await data;
return data;
}
return false;
}
export { accessAPI };
|