From aa71231c2ba1dcfa4acc5ee51c4d17eda3b0d244 Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Tue, 1 Aug 2023 22:32:27 +0200 Subject: [PATCH] Added api versioning & requests to the RequestUtil.js --- src/common/utils/RequestUtil.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/common/utils/RequestUtil.js b/src/common/utils/RequestUtil.js index 9386816..3d38510 100644 --- a/src/common/utils/RequestUtil.js +++ b/src/common/utils/RequestUtil.js @@ -1,7 +1,9 @@ const URL = process.env.NODE_ENV === "production" ? "https://api.licenseapi.de" : "/api"; +const API_VERSION = "v1"; + export const request = async (url, method, body, headers) => { - const response = await fetch(URL + url, { + const response = await fetch(`${URL}/${API_VERSION}${url}`, { method: method, headers: {...headers, "Content-Type": "application/json"}, body: JSON.stringify(body) @@ -20,4 +22,24 @@ export const request = async (url, method, body, headers) => { export const sessionRequest = (url, method, token, body) => { return request(url, method, body, {"Authorization": `Bearer ${token}`}); +} + +export const getRequest = (url) => { + return sessionRequest(url, "GET", localStorage.getItem("sessionToken")); +} + +export const postRequest = (url, body) => { + return sessionRequest(url, "POST", localStorage.getItem("sessionToken"), body); +} + +export const putRequest = (url, body) => { + return sessionRequest(url, "PUT", localStorage.getItem("sessionToken"), body); +} + +export const deleteRequest = (url) => { + return sessionRequest(url, "DELETE", localStorage.getItem("sessionToken")); +} + +export const patchRequest = (url, body) => { + return sessionRequest(url, "PATCH", localStorage.getItem("sessionToken"), body); } \ No newline at end of file