Is there any way to make api calls using web workers in react app?

Viewed 21

is possible to make api calls in separate thread in browser, in some case of invking api call, my app blocking the main thread, i ll share my code, is there any solution

function invoke(method, url, payload) {
const defaultHeaders = {
    'Content-Type': 'application/json',
    Accept: 'application/json'
};
let reqConfigData = {
    method,
    headers: Object.assign({}, defaultHeaders, payload.headers)
    // credentials: 'include'
};
if (requestBodyTypes.indexOf(method) !== -1) {
    reqConfigData.body = reqConfigData.headers['Content-Type'] === 'application/x-www-form-urlencoded'
        ? queryString.stringify(payload.body || {})
        : JSON.stringify(payload.body || {});
}

let endPointUrl = oktaAPIs.indexOf(url) === -1 ? config.apiServer.url : config.authServer.url;

return fetch(`${endPointUrl}/${url}`, reqConfigData)
    .then(validateResponse)
    .then(response => ({ response }))
    .catch(handleError);
}

if possoble, please share an example?

0 Answers
Related