From 4ea3a099b05fa910498bfbf1b2d7387118355472 Mon Sep 17 00:00:00 2001 From: "Ole Mathias Aa. Heggem" Date: Sun, 13 Apr 2025 07:18:45 +0200 Subject: Upgrade bootstrap and rewrite API (#230) --- web/js/nms-fetch.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 web/js/nms-fetch.js (limited to 'web/js/nms-fetch.js') diff --git a/web/js/nms-fetch.js b/web/js/nms-fetch.js new file mode 100644 index 0000000..da2162c --- /dev/null +++ b/web/js/nms-fetch.js @@ -0,0 +1,38 @@ +async function getData(url) { + var data; + const request = new Request(url, { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + }); + + await fetch(request) + .then((response) => response.json()) + .then((json) => { + data = json; + }) + .catch(console.error); + + return data; +} + +async function postData(url, data) { + var data; + const request = new Request(url, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(data) + }); + + await fetch(request) + .then((response) => response.json()) + .then((json) => { + data = json; + }) + .catch(console.error); + + return data; +} -- cgit v1.2.3