summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2016-12-31 13:02:04 -0700
committermo khan <mo@mokhan.ca>2016-12-31 13:02:04 -0700
commitc92a6282b3b99773268830aaaf0de5d259b8ae21 (patch)
tree2b426f3988c4078cd0cd1b8a043de73c9c7e8e2e
parent17326cf4bff2b18938e18bb32944bff5c28f97e5 (diff)
include auth token in POST requests.
-rw-r--r--app/infrastructure/api.js24
1 files changed, 11 insertions, 13 deletions
diff --git a/app/infrastructure/api.js b/app/infrastructure/api.js
index fb9010c..40f02ae 100644
--- a/app/infrastructure/api.js
+++ b/app/infrastructure/api.js
@@ -5,26 +5,24 @@ export default class Api {
}
get(relativeUrl, success) {
- let url = this.buildUrlFor(relativeUrl);
+ const url = this.buildUrlFor(relativeUrl);
this.defaultHeaders((headers) => {
console.log(`GET ${url}`);
- fetch(url, { method: 'GET', headers: headers })
- .then((response) => response.json())
- .then((json) => success(json))
- .catch((error) => console.error(error))
- .done();
+ this.execute(url, { method: 'GET', headers: headers }, success);
});
}
post(relativeUrl, body, success) {
- let url = this.buildUrlFor(relativeUrl);
+ const url = this.buildUrlFor(relativeUrl);
const jsonBody = JSON.stringify(body);
- console.log(`POST ${url}`);
- fetch(url, {
- method: "POST",
- headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' },
- body: jsonBody
- })
+ this.defaultHeaders((headers) => {
+ console.log(`POST ${url}`);
+ this.execute(url, { method: "POST", headers: headers, body: jsonBody }, success);
+ });
+ }
+
+ execute(url, options, success) {
+ fetch(url, options)
.then((response) => response.json())
.then((json) => success(json))
.catch((error) => console.error(error))