cygnal/src/api/index.js

25 lines
706 B
JavaScript
Raw Normal View History

2018-06-25 18:29:57 +02:00
require('es6-promise').polyfill();
require('isomorphic-fetch');
// With trailing slash
export const BASE_URL = process.env.API_BASE_URL || 'http://127.0.0.1:8081/'; // TODO
export function saveReport(type, lat, lng) {
return fetch(`${BASE_URL}api/v1/reports`, {
method: 'POST',
body: JSON.stringify({
type,
lat,
lng,
}),
2018-06-26 11:04:23 +02:00
})
.catch(exc => console.error(`Unable to post report: ${exc}.`));
2018-06-25 18:29:57 +02:00
}
export function getReports() {
2018-06-26 11:04:23 +02:00
return fetch(`${BASE_URL}api/v1/reports`)
.then(response => response.json())
.then(response => response.data)
.catch(exc => console.error(`Unable to fetch reports: ${exc}.`));
2018-06-25 18:29:57 +02:00
}