return-fetch-json
TypeScript icon, indicating that this package has built-in type declarations

0.4.6 • Public • Published

️return-fetch-json

An extended function of [return-fetch](https://github.com/deer-develop/return-fetch) to serialize request body and deserialize response body as json.
See Documentation or See Demo

CI Test Coverage npm version Bundle Size MIT license

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);

Installation

Package Manager

Via npm

npm install return-fetch-json

Via yarn

yarn add return-fetch-json

Via pnpm

pnpm add return-fetch-json

<script> tag

<!--
  Pick your favourite CDN:
    - https://unpkg.com/return-fetch-json
    - https://cdn.jsdelivr.net/npm/return-fetch-json
    - https://www.skypack.dev/view/return-fetch-json
    - …
-->

<!-- UMD import as window.returnFetchJson -->
<script src="https://unpkg.com/return-fetch-json"></script>

<!-- Modern import -->
<script type="module">
  import returnFetchJson from 'https://cdn.skypack.dev/return-fetch-json/dist/index.js'

  // ... //
</script>

Demo

Run on Stickblitz.

Package Sidebar

Install

npm i return-fetch-json

Weekly Downloads

35

Version

0.4.6

License

MIT

Unpacked Size

20.2 kB

Total Files

11

Last publish

Collaborators

  • myeongjae.kim