Skip to content

Instantly share code, notes, and snippets.

View debajyoti-thetaonelab's full-sized avatar

Debajyoti Bhaumik debajyoti-thetaonelab

View GitHub Profile
@debajyoti-thetaonelab
debajyoti-thetaonelab / fetchAPI.js
Last active January 14, 2019 15:06 — forked from sibu-github/fetchAPI.js
A common function which can handle all fetch calls with proper error handling
/**
* Common fetchAPI which can handle GET and POST method
* Content-Type is set to 'application/json'
* payload should be in JSON format
*/
export async function fetchAPI(url, data, method = 'POST') {
// raise an error if url is missig
if (!url) {
throw new Error('url is missing');
}