Utilities for Request.
npm install --save extra-request
# or
yarn add extra-requestimport { 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)interface IRequestOptions {
url: URL
headers: Headers
payload?: BodyInit
signal?: AbortSignal
keepalive?: boolean
redirect?: RequestRedirect
cache?: RequestCache
priority?: RequestPriority
}
type IRequestOptionsTransformer = (options: IRequestOptions) => RequestOptionsfunction get(...transformers: Array<IRequestOptionsTransformer | Falsy>): Requestfunction head(...transformers: Array<IRequestOptionsTransformer | Falsy>: Requestfunction post(...transformers: Array<IRequestOptionsTransformer | Falsy>): Requestfunction put(...transformers: Array<IRequestOptionsTransformer | Falsy>): Requestfunction patch(...transformers: Array<IRequestOptionsTransformer | Falsy>): Requestfunction del(...transformers: Array<IRequestOptionsTransformer | Falsy>): Requestfunction query(...transformers: Array<IRequestOptionsTransformer | Falsy>): Requestfunction request(
method: string
, ...transformers: Array<IRequestOptionsTransformer | Falsy>
): Requestfunction pipeRequestOptionsTransformers(
...transformers: Array<IRequestOptionsTransformer | Falsy>
): IRequestOptionsfunction url(...urls: NonEmptyArray<string | URL>): IRequestOptionsTransformerfunction text(payload: string): IRequestOptionsTransformerfunction json<T extends JSONValue | JSONSerializable<any>>(
payload: T
): IRequestOptionsTransformerfunction csv<Field extends string>(
header: NonEmptyArray<Field>
, data: Array<Record<Field, number | string>>
): IRequestOptionsTransformerfunction signal(signal: AbortSignal): IRequestOptionsTransformerfunction header(name: string, value: string): IRequestOptionsTransformerfunction appendHeader(name: string, value: string): IRequestOptionsTransformerfunction headers<T extends Record<string, string>>(
headers: T
): IRequestOptionsTransformer
function headers(
headers: Headers
): IRequestOptionsTransformerfunction host(host: string): IRequestOptionsTransformerfunction hostname(hostname: string): IRequestOptionsTransformerfunction port(port: number): IRequestOptionsTransformerfunction pathname(pathname: string): IRequestOptionsTransformerfunction appendPathname(pathname: string): IRequestOptionsTransformerfunction search(search: string): IRequestOptionsTransformerfunction searchParam(
name: string
, value: string | number
): IRequestOptionsTransformerfunction appendSearchParam(
name: string
, value: string | number
): IRequestOptionsTransformerfunction searchParams<T extends Record<string, string | number | undefined>>(
searchParams: T
): IRequestOptionsTransformerfunction formDataField(
name: string
, value: string | string[] | Blob
): IRequestOptionsTransformerfunction basicAuth(username: string, password: string): IRequestOptionsTransformerfunction bearerAuth(token: string): IRequestOptionsTransformerfunction keepalive(keepalive: boolean = true): IRequestOptionsTransformerfunction redirect(redirect: RequestRedirect): IRequestOptionsTransformerfunction body(body: BodyInit): IRequestOptionsTransformerfunction cache(cache: RequestCache): IRequestOptionsTransformerfunction priority(priority: RequestPriority): IRequestOptionsTransformer