blob: 243edf7c134646ee020d2026542bab7af4a5547c (
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
|
// Description: This file contains functions to access the API with JWT authentication.
/**
* 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(`/api${endpoint}`, {
method: method,
body: body,
});
if (response.ok) {
let data = await response.json();
data = await data;
return data;
}
return false;
}
|