🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

setch

Package Overview
Dependencies
Maintainers
0
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

setch

Simplest fetch wrapper

4.0.0
latest
Source
npm
Version published
Maintainers
0
Created
Source

Simplest fETCH wrapper I could come up with to reduce boilerplate code when using fetch on a daily basis while keeping as much compatibility with standard as possible

features

  • creating setch functions with default options
  • flexible status code checks with proper errors
  • aliases to common content-type strings

install

npm i setch

usage

// basics, see docs for details
import { setch, makeSetch, mime } from 'setch'

// capture common parameters for reuse
const setchMyApi = makeSetch(
  baseUrlString, // final url will be baseUrlString + urlString
  { headers: { accept: mime.json } }, // will be merged with options, headers too
  200, // expected status, will throw if it isn't, can be overridden and flexible, see docs
)
// same as setch, but uses captured parameters too
const json = await setchMyApi(urlString, options).then(r => r.json())

docs

generated typedoc

but there's not much to it really, have a look at source if you're curious :^)

Keywords

simple

FAQs

Package last updated on 02 Dec 2024

Did you know?

Socket

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.

Install

Related posts