Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

heartsradiant/fetch-node

Repository files navigation

fetch-node

Thin wrapper over node-fetch. Sister libray of @asd14/fetch-browser.

Install

npm i @asd14/fetch-node

Initialize

import { set } from "@asd14/fetch-node"
set({
 // Throws if not set and using relative paths
 baseURL: "http://localhost",
})

Default headers

import { set } from "@asd14/fetch-node"
set({
 // Persistent headers
 headers: {
 // Library defaults
 "accept": "application/json",
 "content-type": "application/json",
 // Set JWT for authorized requests
 authorization: "signed-payload-with-base64-over",
 },
})

Query string parameters

There is no built-in way to handle query params but you can set a custom transform function.

import { set } from "@asd14/fetch-node"
import { stringify } from "qs"
set({
 // Throws if query params passed and no stringify function defined
 queryStringifyFn: source =>
 stringify(source, {
 allowDots: true,
 encode: false,
 arrayFormat: "brackets",
 strictNullHandling: true,
 })
})

GET

import { GET } from "@asd14/fetch-node"
const myIP = await GET("https://api.ipify.org", {
 query: {
 format: "json"
 }
})
// => {"ip":"213.127.80.141"}

PATCH

POST

DELETE

MULTIPART

Changelog

See the releases section for details.

About

Thin wrapper over `node-fetch`

Resources

License

Stars

Watchers

Forks

Packages

Contributors

Languages

  • JavaScript 100.0%

AltStyle によって変換されたページ (->オリジナル) /