@rojiwon123/fetch
v1.0.3
Published
Fetch API wrapped around the original fetch function
Downloads
2
Readme
Fetch API
Fetch API wrapped around the original fetch function
Installation
npm i @rojiwon123/fetch
Example
import fetch from "@rojiwon123/fetch";
void fetch.request
.query({ url: "http://localhost:3000", method: "GET" })
.then(fetch.response.match({ 200: fetch.response.none() }))
.then(console.log); // null
// request headers content-type value is `application/json; charset=utf-8`
void fetch.request
.json({
url: "http://localhost:3000",
body: { test: "test" },
method: "POST",
})
.then(
fetch.response.match({
201: fetch.response.json((i) => i), // status 201 case
_: fetch.response.text((i) => i), // default case
}),
)
.then(console.log); // log response body