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

18 lines
523 B
JavaScript
Raw Normal View History

2016-02-14 19:19:11 +00:00
import token from './token';
2016-02-06 12:42:19 +00:00
2016-05-05 18:51:31 +01:00
export default async function request(url, method = 'GET', data = {}, CIToken) {
CIToken = CIToken || await token.get();
2016-02-14 19:19:11 +00:00
const fullURL = url.query({ 'circle-token': CIToken }).toString();
2016-02-06 12:42:19 +00:00
let fetchParams = {
method,
headers: {
'Accept': 'application/json',
},
};
if (method !== 'GET' && method !== 'HEAD') {
fetchParams.body = JSON.stringify(data);
2016-05-05 18:51:31 +01:00
fetchParams.headers['Content-Type'] = 'application/json';
2016-02-06 12:42:19 +00:00
}
2016-05-05 18:51:31 +01:00
return await fetch(fullURL, fetchParams);
2016-02-06 12:42:19 +00:00
}