fetch-result-please

0.2.0 • Public • Published

Fetch Result Please!

const result = await fetchRP(api.$fetch())

Project's branding image

fetch-result-please TypeScript heart icon

npm version npm downloads Codecov Bundlejs TypeDoc

Overview

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.

Features

  • 👌 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

Usage

Install package

# npm
npm install fetch-result-please

# bun
bun add fetch-result-please

# pnpm
pnpm install fetch-result-please

Import and use

// 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' })

Credits

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.

License

License

Readme

Keywords

none

Package Sidebar

Install

npm i fetch-result-please

Weekly Downloads

97

Version

0.2.0

License

MIT

Unpacked Size

10.8 kB

Total Files

5

Last publish

Collaborators

  • namesmt