UNPKG

media_player_wrapper

Version:
55 lines (47 loc) 1.28 kB
const baseUrl = "insert base url"; const API = { getData(url) { console.log("getData", url); return fetch(url, { method: "GET", headers: { "content-type": "application/json" } }) .then(this.checkStatus) .then(response => (response === undefined ? null : response.json())); }, postData(url, body) { console.log("postData", url); return fetch(url, { method: "POST", headers: { "content-type": "multipart/form-data" //may change depending on api }, body: body }) .then(this.checkStatus) .then(response => (response === undefined ? null : response.json())); }, deleteData(url, body) { console.log("deleteData", url); return fetch(url, { method: "DELETE", body: body }) .then(this.checkStatus) .then(response => (response === undefined ? null : response.json())); }, checkStatus(response) { if (response.ok) { if (response.status >= 200 && response.status < 300) return response; else if (response.status === 404) { throw Error(response.statusText); }else{ throw Error("Something went wrong. try again later!"); } } else { throw Error("404 Page not found!"); } } };