Files
react-native-code-push/request-fetch-adapter.js
2015-12-23 21:55:25 -08:00

31 lines
720 B
JavaScript

let request = async (verb, url, body, callback) => {
if (typeof body === "function") {
callback = body;
body = null;
}
var headers = {
"Accept": "application/json",
"Content-Type": "application/json"
};
if (body && typeof body === "object") {
body = JSON.stringify(body);
}
try {
var statusCode;
let response = await fetch(url, {
method: verb,
headers: headers,
body: body
});
let statusCode = response.status;
let body = await response.text();
callback(null, {statusCode: statusCode, body: body});
} catch (err) {
callback(err);
}
}