aboutsummaryrefslogtreecommitdiff
path: root/app/src/helpers/api.js
diff options
context:
space:
mode:
authorParker <contact@pkrm.dev>2024-11-10 16:36:16 -0600
committerParker <contact@pkrm.dev>2024-11-10 16:36:16 -0600
commit691aa744a0398f185b3ca98a36fbd83806c7786c (patch)
tree7840f31c30bb6eda903abd6bbf4dbfb2ac590966 /app/src/helpers/api.js
parent8941213c8d94f3ad84e07e467e78105dc7fed734 (diff)
TOO MUCH STUFF
Diffstat (limited to 'app/src/helpers/api.js')
-rw-r--r--app/src/helpers/api.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/app/src/helpers/api.js b/app/src/helpers/api.js
new file mode 100644
index 0000000..0381f18
--- /dev/null
+++ b/app/src/helpers/api.js
@@ -0,0 +1,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 }; \ No newline at end of file