allow makeAPIRequest() to handle JSON requests
This commit is contained in:
parent
e1ea41b6d1
commit
25eeae34ba
@ -6,12 +6,22 @@
|
||||
* @returns a Promise, which resolves when the server can be reached and responds without an error
|
||||
* and rejects otherwise
|
||||
*/
|
||||
async function makeAPIRequest(endpoint, body) {
|
||||
async function makeAPIRequest(endpoint, body, options={}) {
|
||||
let fetchOptions = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
};
|
||||
|
||||
if (options["content"] === 'json') {
|
||||
fetchOptions["headers"]["Content-Type"] = 'application/json'
|
||||
fetchOptions["body"] = JSON.stringify(body)
|
||||
} else {
|
||||
fetchOptions["body"] = new URLSearchParams(body);
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const fetchOptions = {
|
||||
method: "POST",
|
||||
body: new URLSearchParams(body)
|
||||
};
|
||||
|
||||
fetch("/api/v1/" + endpoint, fetchOptions).then(response => {
|
||||
const responseCode = response.status;
|
||||
|
Loading…
Reference in New Issue
Block a user