Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 2e39fbf

Browse files
author
Will Anderson
committed
Add temporary fetch adapter for use by the SDK
1 parent 99d2aed commit 2e39fbf

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

request-fetch-adapter.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module.exports.request = function request(verb, url, body, callback) {
2+
if (typeof body === "function") {
3+
callback = body;
4+
body = null;
5+
}
6+
7+
var headers = {
8+
'Accept': 'application/json',
9+
'Content-Type': 'application/json'
10+
};
11+
12+
if (body && typeof body === "object") {
13+
body = JSON.stringify(body);
14+
}
15+
16+
var statusCode;
17+
18+
fetch(url, {
19+
method: verb,
20+
headers: headers,
21+
body: body
22+
}).then(function(response) {
23+
statusCode = response.status;
24+
return response.text();
25+
}).then(function(body) {
26+
callback(null, {statusCode: statusCode, body: body});
27+
}).catch(function(err) {
28+
callback(err);
29+
});
30+
}

0 commit comments

Comments
 (0)