This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
Sphere/app/api/request.js
2016-05-05 18:51:31 +01:00

17 lines
523 B
JavaScript

import token from './token';
export default async function request(url, method = 'GET', data = {}, CIToken) {
CIToken = CIToken || await token.get();
const fullURL = url.query({ 'circle-token': CIToken }).toString();
let fetchParams = {
method,
headers: {
'Accept': 'application/json',
},
};
if (method !== 'GET' && method !== 'HEAD') {
fetchParams.body = JSON.stringify(data);
fetchParams.headers['Content-Type'] = 'application/json';
}
return await fetch(fullURL, fetchParams);
}