mirror of
https://github.com/plankanban/planka.git
synced 2025-07-23 07:09:44 +02:00
Initial commit
This commit is contained in:
commit
5ffef61fe7
613 changed files with 91659 additions and 0 deletions
35
client/src/api/http.js
Executable file
35
client/src/api/http.js
Executable file
|
@ -0,0 +1,35 @@
|
|||
import { fetch } from 'whatwg-fetch';
|
||||
|
||||
import Config from '../constants/Config';
|
||||
|
||||
const http = {};
|
||||
|
||||
// TODO: all methods
|
||||
['POST'].forEach((method) => {
|
||||
http[method.toLowerCase()] = (url, data, headers) => {
|
||||
const formData = Object.keys(data).reduce((result, key) => {
|
||||
result.append(key, data[key]);
|
||||
|
||||
return result;
|
||||
}, new FormData());
|
||||
|
||||
return fetch(`${Config.API_URL}${Config.API_PATH}${url}`, {
|
||||
method,
|
||||
headers,
|
||||
body: formData,
|
||||
})
|
||||
.then((response) => response.json().then((body) => ({
|
||||
body,
|
||||
isError: response.status !== 200,
|
||||
})))
|
||||
.then(({ body, isError }) => {
|
||||
if (isError) {
|
||||
throw body;
|
||||
}
|
||||
|
||||
return body;
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
export default http;
|
Loading…
Add table
Add a link
Reference in a new issue