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

34 lines
677 B
JavaScript

"use strict";
module.exports = {
async request(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 {
const response = await fetch(url, {
method: verb,
headers: headers,
body: body
});
const statusCode = response.status;
const body = await response.text();
callback(null, { statusCode, body });
} catch (err) {
callback(err);
}
}
};