1.4.1 • Published 2 years ago

request-it-client v1.4.1

Weekly downloads
3
License
MIT
Repository
github
Last release
2 years ago

RequestIt Client

A stupidly simple HTTP client for Node-JS that should just work. Built-in support for cookies, JSON, and may follow up to a max of 20 redirects.

It is expected to deprecate this module in favor of Deno's native fetch or node-fetch by end of year 2022.

If you are using this module in production, we suggest upgrading to v2, gradually moving to the Fetch API, and then replacing this lib with native or node-fetch.

We will accept bug reports and patches through Nov 2022.

Usage

Install via NPM and require in your project.

Fetch API (Recommended migration path)

const { fetch } = require('request-it-client')

;(async function main () {
  const res = await fetch('https://reqres.in/api/users/2')
  const body = await res.json()

  console.log(body.data.first_name) // expected result: Janet
})()

RequestIt interface

const { RequestIt } = require('request-it-client')

;(async function main () {
  const res = await RequestIt.go('https://reqres.in/api/users/2')

  console.log(res.body.data.first_name) // expected result: Janet
})()

RequestIt API

Class: RequestIt

Node.js library for Promise-based, asynchronous http/s requests.

Constructors

constructor

new RequestIt(options?)

Parameters
NameType
optionsRequestOptions

Properties

cookieJar

cookieJar: RequestItCookieJar


maxRedirects

maxRedirects: number


options

options: RequestOptions

Methods

delete

delete(options?): Promise<IncomingMessage>

Parameters
NameType
optionsstring | URL | RequestOptions
Returns

Promise<IncomingMessage>


get

get(options?): Promise<IncomingMessage>

Parameters
NameType
optionsstring | URL | RequestOptions
Returns

Promise<IncomingMessage>


go

go(options?): Promise<IncomingMessage>

Base method for making a request.

Parameters
NameType
options?string | URL | RequestOptions
Returns

Promise<IncomingMessage>

The IncomingMessage object with parsed body and RawBody.


patch

patch(options?): Promise<IncomingMessage>

Parameters
NameType
optionsstring | URL | RequestOptions
Returns

Promise<IncomingMessage>


post

post(options?): Promise<IncomingMessage>

Parameters
NameType
optionsstring | URL | RequestOptions
Returns

Promise<IncomingMessage>


put

put(options?): Promise<IncomingMessage>

Parameters
NameType
optionsstring | URL | RequestOptions
Returns

Promise<IncomingMessage>


delete

Static delete(options?): Promise<IncomingMessage>

Parameters
NameType
optionsstring | URL | RequestOptions
Returns

Promise<IncomingMessage>


get

Static get(options?): Promise<IncomingMessage>

Parameters
NameType
optionsstring | URL | RequestOptions
Returns

Promise<IncomingMessage>


go

Static go(options?): Promise<IncomingMessage>

Parameters
NameType
optionsstring | URL | RequestOptions
Returns

Promise<IncomingMessage>


patch

Static patch(options?): Promise<IncomingMessage>

Parameters
NameType
optionsstring | URL | RequestOptions
Returns

Promise<IncomingMessage>


post

Static post(options?): Promise<IncomingMessage>

Parameters
NameType
optionsstring | URL | RequestOptions
Returns

Promise<IncomingMessage>


put

Static put(options?): Promise<IncomingMessage>

Parameters
NameType
optionsstring | URL | RequestOptions
Returns

Promise<IncomingMessage>

Class: RequestItCookieJar

Hierarchy

  • CookieJar

    RequestItCookieJar

Constructors

constructor

new RequestItCookieJar(store?, options?)

Parameters
NameType
store?Store
options?Options
Inherited from

CookieJar.constructor

Properties

store

store: RequestItStore

Methods

findCookie

findCookie(domain, path, key): Promise<Cookie>

Parameters
NameType
domainstring
pathstring
keystring
Returns

Promise<Cookie>


getCookieString

getCookieString(currentUrl, options?): Promise<string>

Parameters
NameType
currentUrlstring
options?Function | GetCookiesOptions
Returns

Promise<string>

Overrides

CookieJar.getCookieString


setCookie

setCookie(cookieOrString, currentUrl, options?): Promise<Cookie>

Parameters
NameType
cookieOrStringstring | Cookie
currentUrlstring
options?Function | SetCookieOptions
Returns

Promise<Cookie>

Overrides

CookieJar.setCookie


fromCookieJar

Static fromCookieJar(cookieJar): RequestItCookieJar

Parameters
NameType
cookieJarCookieJar
Returns

RequestItCookieJar

Class: RequestItHeaders

Hierarchy

  • Map<string, string>

    RequestItHeaders

Implements

  • Headers

Constructors

constructor

new RequestItHeaders(init)

Parameters
NameType
initIterable<readonly string, string> | Record<string, string | string[]>
Overrides

Map<string, string\>.constructor

Properties

forEach

forEach: (callbackfn: (value: string, key: string, parent: RequestItHeaders) => void, thisArg?: any) => void

Type declaration

▸ (callbackfn, thisArg?): void

####### Parameters

NameType
callbackfn(value: string, key: string, parent: RequestItHeaders) => void
thisArg?any

####### Returns

void

Implementation of

Headers.forEach

Overrides

Map.forEach

Methods

append

append(name, value): void

Parameters
NameType
namestring
valuestring
Returns

void

Implementation of

Headers.append


set

set(name, value): RequestItHeaders

Parameters
NameType
namestring
valuestring
Returns

RequestItHeaders

Implementation of

Headers.set

Overrides

Map.set

Class: RequestItResponse

Implements

  • Response

Constructors

constructor

new RequestItResponse(msg)

Parameters
NameType
msgIncomingMessage

Accessors

body

get body(): ReadableStream<Uint8Array>

Returns

ReadableStream<Uint8Array>

Implementation of

Response.body


bodyUsed

get bodyUsed(): boolean

Returns

boolean

Implementation of

Response.bodyUsed


cookies

get cookies(): RequestItCookieJar

Because server-side javascript has no global cookie methods.

Returns

RequestItCookieJar


headers

get headers(): RequestItHeaders

Returns

RequestItHeaders

Implementation of

Response.headers


ok

get ok(): boolean

Returns

boolean

Implementation of

Response.ok


redirected

get redirected(): boolean

Returns

boolean

Implementation of

Response.redirected


status

get status(): number

Returns

number

Implementation of

Response.status


statusText

get statusText(): string

Returns

string

Implementation of

Response.statusText


type

get type(): ResponseType

Always basic; server side has no respect for cors.

Returns

ResponseType

Implementation of

Response.type


url

get url(): string

Returns

string

Implementation of

Response.url

Methods

arrayBuffer

arrayBuffer(): Promise<ArrayBuffer>

Returns

Promise<ArrayBuffer>

Implementation of

Response.arrayBuffer


blob

blob(): never

Unsupported method.

Returns

never

Implementation of

Response.blob


clone

clone(): RequestItResponse

Returns

RequestItResponse

Implementation of

Response.clone


formData

formData(): never

Unsupported method.

Returns

never

Implementation of

Response.formData


json

json(): Promise<any>

Returns

Promise<any>

Implementation of

Response.json


text

text(): Promise<string>

Returns

Promise<string>

Implementation of

Response.text

Interface: IncomingMessage

Hierarchy

  • IncomingMessage

    IncomingMessage

Properties

body

body: any


cookieJar

cookieJar: RequestItCookieJar


rawBody

rawBody: Buffer


rawResponse

rawResponse: Buffer


rawText

rawText: string


redirected

redirected: boolean


url

url: string

Overrides

http.IncomingMessage.url

Methods

json

json(): any

Returns

any

Interface: RequestItStore

Hierarchy

  • Store

    RequestItStore

Methods

findCookie

findCookie(domain, path, key): Promise<Cookie>

Parameters
NameType
domainstring
pathstring
keystring
Returns

Promise<Cookie>

Overrides

Store.findCookie

Interface: RequestOptions

Hierarchy

  • RequestOptions

    RequestOptions

Properties

body

Optional body: string | object | any[] | Buffer


cookieJar

Optional cookieJar: RequestItCookieJar | CookieJar


followRedirect

Optional followRedirect: boolean


form

Optional form: URLSearchParams | { key: string: string | boolean | number; }


json

Optional json: object | any[]


maxRedirects

Optional maxRedirects: number


params

Optional params: Object

Index signature

key: string: string | boolean | number


rejectBadJson

Optional rejectBadJson: boolean


responseType

Optional responseType: "json"


url

Optional url: string | URL

2.0.0-beta2

2 years ago

2.0.0-beta

2 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.2.1

4 years ago

1.0.0

4 years ago