Files
react-native-code-push/request-fetch-adapter.js
Geoffrey Goh 45c4e74d1a feedback
2015-12-24 01:00:17 -08:00

30 lines
680 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 {
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);
}
}