Skip to content
Snippets Groups Projects
Verified Commit 763be9f1 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

fix: check header by rest api

parent e440a937
No related branches found
No related tags found
No related merge requests found
...@@ -94,7 +94,10 @@ class RestAPI extends Server { ...@@ -94,7 +94,10 @@ class RestAPI extends Server {
write: { write: {
init: { init: {
method: "POST", method: "POST",
headers: null, headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
}, },
responseCallback: null, responseCallback: null,
acceptedStatus: [200, 201], acceptedStatus: [200, 201],
...@@ -118,7 +121,9 @@ class RestAPI extends Server { ...@@ -118,7 +121,9 @@ class RestAPI extends Server {
read: { read: {
init: { init: {
method: "GET", method: "GET",
headers: null, headers: {
Accept: "application/json"
},
}, },
path: null, path: null,
responseCallback: null, responseCallback: null,
...@@ -141,10 +146,9 @@ class RestAPI extends Server { ...@@ -141,10 +146,9 @@ class RestAPI extends Server {
read() { read() {
let init = this.getOption("read.init"); let init = this.getOption("read.init");
if (!isObject(init)) init = {}; if (!isObject(init)) init = {};
if (!(init["headers"] instanceof Headers)) { if (!(init["headers"] instanceof Headers) && !isObject(init["headers"])) {
init["headers"] = new Headers(); init["headers"] = new Headers();
init["headers"].append("Accept", "application/json"); init["headers"].append("Accept", "application/json");
init["headers"].append("X-Requested-With", "XMLHttpRequest");
} }
if (!init["method"]) init["method"] = "GET"; if (!init["method"]) init["method"] = "GET";
...@@ -166,7 +170,7 @@ class RestAPI extends Server { ...@@ -166,7 +170,7 @@ class RestAPI extends Server {
write() { write() {
let init = this.getOption("write.init"); let init = this.getOption("write.init");
if (!isObject(init)) init = {}; if (!isObject(init)) init = {};
if (!(init["headers"] instanceof Headers)) { if (!(init["headers"] instanceof Headers) && !isObject(init["headers"])) {
init["headers"] = new Headers(); init["headers"] = new Headers();
init["headers"].append("Accept", "application/json"); init["headers"].append("Accept", "application/json");
init["headers"].append("Content-Type", "application/json"); init["headers"].append("Content-Type", "application/json");
...@@ -206,6 +210,10 @@ class RestAPI extends Server { ...@@ -206,6 +210,10 @@ class RestAPI extends Server {
function fetchData(init, key, callback) { function fetchData(init, key, callback) {
let response; let response;
if (init?.headers === null) {
init.headers = new Headers();
}
return fetch(this.getOption(`${key}.url`), init) return fetch(this.getOption(`${key}.url`), init)
.then((resp) => { .then((resp) => {
response = resp; response = resp;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment