![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Modern fetch-based HTTP client for the browser.
fetch + request abortion + timeout support + request and response interceptions
import Fennch from "fennch";
const api = Fennch({
baseUri: "http://awesome.app/api"
})
async function apiCall() {
const result = await api.get("/awesome-data", {
params: {
awesome: "really",
params: "cool"
}
});
/* ###### Under the hood ######
const result = await fetch("http://awesome.app/api/awesome-data?awesome=really¶ms=cool", {
method: "GET"
})
return {
...response,
body: await response.json() // if Content-Type is 'application/json'
}
#############################
*/
/*
`result` is a FResponse object which is Proxy that wraps native Response object.
`result.headers` and `result.body` is already parsed and can accessed right away.
*/
console.log(result.body) => /* => Awesome response! */
}
const api = Fennch({
baseUri: "http://awesome.app/api"
});
const MySuperComponent = {
currentRequest: null,
handleUserAbort(req) {
this.currentRequest.abort();
},
async apiCall() {
this.currentRequest = api.get("/awesome-data", {
params: {
awesome: "really",
params: "cool"
}
});
let result;
try {
result = await currentRequest;
} catch (err) {
result = err;
}
return result;
}
};
// I want make a request
MySuperComponent.apiCall()
.then(res => res)
.catch(err => {
console.log(err); // => 'Request aborted'
});
// Oh, wait, I changed my mind!
MySuperComponent.handleUserAbort();
// Global timeout
const api = Fennch({
baseUri: "http://awesome.app/api",
timeout: 10000
});
async function apiCall() {
try {
await api.get("/awesome-data", {
params: {
awesome: "really",
params: "cool"
}
});
} catch (err) {
// If request pednding more than 10 sec
console.log(err.toString()) // -> "Timeout exceeded"
}
}
// Timeout per-request, overrides global value
async function apiCallWithTimeout() {
try {
await api.get("/awesome-data", {
timeout: 20000,
params: {
awesome: "really",
params: "cool"
}
});
} catch (err) {
// If request pednding more than 20 sec
console.log(err.toString()) // -> "Timeout exceeded"
}
}
You can register any number of interceptors using register()
method.
It returns function that can be used to unregister this interceptor.
const unregister = fennch.interceptor.register({
request(request) {}, // Must return FRequest object, for example `request` that passed as an argument
requestError(error) {},
response(response) {}, // Must return FResponse object, for example `request` that passed as an argument
responseError(error) {}
})
unregister() // unregister interceptor
Simple example:
const api = Fennch({
baseUri: "http://awesome.app/api"
});
const unregister = api.interceptor.register({
request(request) {
/* Making some tweaks in request */
/*...*/
return request // Interceptor *must* return request
},
requestError(request) {
/* Making some tweaks in request */
/*...*/
return Promise.resolve(request)
},
response(response) {
/* Making some tweaks in response */
/*...*/
return response // Interceptor *must* return response
},
responseError(err) {
/* If request is aborted adding `cancel` property to error */
if (err.toString() === 'AbortError') {
err.cancel = true
return Promise.reject(err)
}
if (!err.response && err.message === 'Network Error') {
err = networkErrorResolver(err)
return Promise.resolve(err)
}
return err
}
})
Example for refreshing authorization token using interceptor:
const accessToken = "some_access_token"
const refreshToken = "some_refresh_token"
const api = Fennch({
baseUri: "http://awesome.app/api",
headers: {
"Content-Type": "application/json",
Accept: 'application/json',
Authorization: `Bearer ${accessToken}`
},
});
api.interceptors.register({
async response(response) {
if (response.status === 401) {
try {
const refreshed = await api.post('/refresh_token', {
headers: {
Authorization: `Bearer ${refreshToken}`
}
})
const newAccessToken = refreshed.body.token
const request = response.request
request.headers.Authorization = `Bearer ${newAccessToken}`
return api.req(request)
} catch (error) {
return Promise.reject(error)
}
}
}
})
FAQs
Modern fetch-based HTTP client for the browser and node.js
The npm package fennch receives a total of 82 weekly downloads. As such, fennch popularity was classified as not popular.
We found that fennch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.