RESTfulMC/Lib/src/lib/webRequest.ts
Rainnny7 50b5c8ba4b
Some checks failed
Deploy Lib / docker (ubuntu-latest, 2.44.0) (push) Failing after 1m29s
Cleanup the lib
2024-04-14 16:29:29 -04:00

23 lines
642 B
TypeScript

import { ErrorResponse } from "../types/generic";
const ENDPOINT = "https://mc.rainnny.club"; // The API endpoint to use
/**
* Make a web request to the API.
*
* @param url the endpoint to make the request to
* @returns the promised response
*/
export const makeWebRequest = <T>(endpoint: string): Promise<T> =>
new Promise(async (resolve, reject) => {
const response: Response = await fetch(`${ENDPOINT}/${endpoint}`); // Request the player
const json: any = await response.json();
// Resolve the response
if (response.ok) {
resolve(json as T);
} else {
reject(json as ErrorResponse); // The request failed
}
});