Bug 32939: Set the default header at lower level
Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com> Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
10322566d4
commit
5871db7958
2 changed files with 5 additions and 10 deletions
|
@ -24,19 +24,16 @@ export class ERMAPIClient extends HttpClient {
|
|||
delete: (id) =>
|
||||
this.delete({
|
||||
endpoint: "agreements/" + id,
|
||||
headers: this.getDefaultJSONPayloadHeader(),
|
||||
}),
|
||||
create: (agreement) =>
|
||||
this.post({
|
||||
endpoint: "agreements",
|
||||
body: agreement,
|
||||
headers: this.getDefaultJSONPayloadHeader(),
|
||||
}),
|
||||
update: (agreement, id) =>
|
||||
this.put({
|
||||
endpoint: "agreements/" + id,
|
||||
body: agreement,
|
||||
headers: this.getDefaultJSONPayloadHeader(),
|
||||
}),
|
||||
//count: () => this.count("agreements"), //TODO: Implement count method
|
||||
};
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
class HttpClient {
|
||||
constructor(options = {}) {
|
||||
this._baseURL = options.baseURL || "";
|
||||
this._headers = options.headers || {
|
||||
"Content-Type": "application/json;charset=utf-8",
|
||||
};
|
||||
}
|
||||
|
||||
async _fetchJSON(endpoint, headers = {}, options = {}) {
|
||||
const res = await fetch(this._baseURL + endpoint, {
|
||||
...options,
|
||||
headers: headers,
|
||||
headers: { ...this._headers, ...headers },
|
||||
});
|
||||
|
||||
if (!res.ok) throw new Error(res.statusText);
|
||||
|
@ -18,7 +21,6 @@ class HttpClient {
|
|||
}
|
||||
|
||||
get(params = {}) {
|
||||
console.log(params);
|
||||
return this._fetchJSON(params.endpoint, params.headers, {
|
||||
...params.options,
|
||||
method: "GET",
|
||||
|
@ -50,10 +52,6 @@ class HttpClient {
|
|||
}
|
||||
|
||||
//TODO: Implement count method
|
||||
|
||||
getDefaultJSONPayloadHeader() {
|
||||
return { "Content-Type": "application/json;charset=utf-8" };
|
||||
}
|
||||
}
|
||||
|
||||
export default HttpClient;
|
||||
|
|
Loading…
Reference in a new issue