fetch-result-please helps you get a consumable result from a fetch call with a helper, and a few other features :) (feel free raise requests).
Note: fetch-result-please
focuses on being a minimal, helper function that you can just add-in to your existing fetch calls, if you're building things from scratch, it is recommended that you check out and use a proper custom fetch implementation like ofetch
, ky
, up-fetch
, etc.
- 👌 Smartly parses and return the consumable result from a fetch
Response
. - 🧐 Submit your feature requests, I'll take a look if it fits the scope
# npm
npm install fetch-result-please
# bun
bun add fetch-result-please
# pnpm
pnpm install fetch-result-please
// ESM
import { fetchRP } from 'fetch-result-please'
const fetchTodo = () => fetch('https://jsonplaceholder.typicode.com/todos/1')
const result: { id: number } = await fetchRP(fetchTodo())
// To force a specific response type, pass in `detectResponseType`:
const blobResult: Blob = await fetchRP(fetchTodo(), { detectResponseType: () => 'blob' })
Codes are borrowed from unjs/ofetch, I highly recommend you to try use it first if it's viable for your usecase, fetch-result-please
focuses more to enhance your existing fetch calls fast, especially in cases where it's wonky or not possible to use a custom fetch implementation directly.