An extended function of return-fetch ot serialize request body and deserialize response body as object.
npm install return-fetch-json
An extended function of return-fetch to serialize request body and
deserialize response body as json.
See Documentation
or
See Demo
``ts
import returnFetchJson from "return-fetch-json";
// Create an extended fetch function and use it instead of the global fetch.
export const fetchExtended = returnFetchJson({
jsonParser: JSON.parse, // jsonParser property is omittable. You can use your custom parser.
baseUrl: "https://jsonplaceholder.typicode.com"
});
//////////////////// Use it somewhere ////////////////////
fetchExtended<{ id: number }>("/posts", {
method: "POST",
body: { message: "Hello, world!" },
}).then(it => it.body)
.then(console.log);
`
Via npm
`bash`
npm install return-fetch-json
Via yarn
`bash`
yarn add return-fetch-json
Via pnpm
`bash`
pnpm add return-fetch-json
`html
``
Run on Stickblitz.