export const fetchPathKeys = () => { return fetch("http://localhost:5000/get-path") .then(res => { if(res.status >= 400) { throw new Error("Server responds with error!"); } return res.json(); }).then(data => { return Object.keys(data) }, err => { console.log(err) }); } export const fetchPaths = () => { return fetch("http://localhost:5000/get-path") .then(res => { if(res.status >= 400) { throw new Error("Server responds with error!"); } return res.json(); }).then(data => { return data }, err => { console.log(err) }) } export function savePathToDb(){ let json = JSON.stringify({ "path": { "name": this.state.savePathKey, "coords": this.state.path } }) let reqOptions = { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, body: json } return fetch("http://localhost:5000/set-path", reqOptions) .then(res => { if(res.status >= 400) { throw new Error("Server responds with error!"); } return res.json(); }) .then(data => { return data }, err => { console.log(err) }) }