extra-request
v11.2.0
Published
Utilities for Request
Readme
extra-request
Utilities for Request.
Install
npm install --save extra-request
# or
yarn add extra-requestUsage
import { post } from 'extra-request'
import { url, json } from 'extra-request/transformers'
const req = post(
url('http://example.com')
, json({ hello: 'world' })
)
const res = await fetch(req)API
interface IRequestOptions {
url: URL
headers: Headers
payload?: BodyInit
signal?: AbortSignal
keepalive?: boolean
redirect?: RequestRedirect
cache?: RequestCache
priority?: RequestPriority
}
type IRequestOptionsTransformer = (options: IRequestOptions) => RequestOptionsget
function get(...transformers: Array<IRequestOptionsTransformer | Falsy>): Requesthead
function head(...transformers: Array<IRequestOptionsTransformer | Falsy>: Requestpost
function post(...transformers: Array<IRequestOptionsTransformer | Falsy>): Requestput
function put(...transformers: Array<IRequestOptionsTransformer | Falsy>): Requestpatch
function patch(...transformers: Array<IRequestOptionsTransformer | Falsy>): Requestdel
function del(...transformers: Array<IRequestOptionsTrransformer | Falsy>): Requestrequest
function request(
method: 'GET' | 'HEAD' | 'PUT' | 'POST' | 'PATCH' | 'DELETE'
, ...transformers: Array<IRequestOptionsTransformer | Falsy>
): RequestpipeRequestOptionsTransformers
function pipeRequestOptionsTransformers(
...transformers: Array<IRequestOptionsTransformer | Falsy>
): IRequestOptionsTransformers
url
function url(...urls: NonEmptyArray<string | URL>): IRequestOptionsTransformertext
function text(payload: string): IRequestOptionsTransformerjson
function json<T extends JSONValue | JSONSerializable<any>>(
payload: T
): IRequestOptionsTransformercsv
function csv<Field extends string>(
header: NonEmptyArray<Field>
, data: Array<Record<Field, number | string>>
): IRequestOptionsTransformersignal
function signal(signal: AbortSignal): IRequestOptionsTransformerheader
function header(name: string, value: string): IRequestOptionsTransformerappendHeader
function appendHeader(name: string, value: string): IRequestOptionsTransformerheaders
function headers<T extends Record<string, string>>(
headers: T
): IRequestOptionsTransformerhost
function host(host: string): IRequestOptionsTransformerhostname
function hostname(hostname: string): IRequestOptionsTransformerport
function port(port: number): IRequestOptionsTransformerpathname
function pathname(pathname: string): IRequestOptionsTransformerappendPathname
function appendPathname(pathname: string): IRequestOptionsTransformersearch
function search(search: string): IRequestOptionsTransformersearchParam
function searchParam(
name: string
, value: string | number
): IRequestOptionsTransformerappendSearchParam
function appendSearchParam(
name: string
, value: string | number
): IRequestOptionsTransformersearchParams
function searchParams<T extends Record<string, string | number | undefined>>(
searchParams: T
): IRequestOptionsTransformerformDataField
function formDataField(
name: string
, value: string | string[] | Blob
): IRequestOptionsTransformerbasicAuth
function basicAuth(username: string, password: string): IRequestOptionsTransformerbearerAuth
function bearerAuth(token: string): IRequestOptionsTransformerkeepalive
function keepalive(keepalive: boolean = true): IRequestOptionsTransformerredirect
function redirect(redirect: RequestRedirect): IRequestOptionsTransformerbody
function body(body: BodyInit): IRequestOptionsTransformercache
function cache(cache: RequestCache): IRequestOptionsTransformerpriority
function priority(priority: RequestPriority): IRequestOptionsTransformer