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
};
}
}
-export default ERMAPIClient;
\ No newline at end of file
+export default ERMAPIClient;
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);
}
get(params = {}) {
- console.log(params);
return this._fetchJSON(params.endpoint, params.headers, {
...params.options,
method: "GET",
}
//TODO: Implement count method
-
- getDefaultJSONPayloadHeader() {
- return { "Content-Type": "application/json;charset=utf-8" };
- }
}
export default HttpClient;