JSFiddle - React, Tailwind, and code Playground
by brigand
JavaScript
let api = (url, method, body = null) => {
let params = {
"credentials": "include",
headers,
"method": method,
body
}
fetch(url, params)
.then(res => res.json()) // expecting a json response
.then(json => {
console.log(json);
})
.catch(err => {
console.log(err);
});
};
let get = (url) => {
api(url, "GET");
};
let POST = (url, body) => {
api(url, "POST", body);
};
get(url);