request-it-client v1.4.1
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
| Name | Type |
|---|---|
options | RequestOptions |
Properties
cookieJar
• cookieJar: RequestItCookieJar
maxRedirects
• maxRedirects: number
options
• options: RequestOptions
Methods
delete
▸ delete(options?): Promise<IncomingMessage>
Parameters
| Name | Type |
|---|---|
options | string | URL | RequestOptions |
Returns
Promise<IncomingMessage>
get
▸ get(options?): Promise<IncomingMessage>
Parameters
| Name | Type |
|---|---|
options | string | URL | RequestOptions |
Returns
Promise<IncomingMessage>
go
▸ go(options?): Promise<IncomingMessage>
Base method for making a request.
Parameters
| Name | Type |
|---|---|
options? | string | URL | RequestOptions |
Returns
Promise<IncomingMessage>
The IncomingMessage object with parsed body and RawBody.
patch
▸ patch(options?): Promise<IncomingMessage>
Parameters
| Name | Type |
|---|---|
options | string | URL | RequestOptions |
Returns
Promise<IncomingMessage>
post
▸ post(options?): Promise<IncomingMessage>
Parameters
| Name | Type |
|---|---|
options | string | URL | RequestOptions |
Returns
Promise<IncomingMessage>
put
▸ put(options?): Promise<IncomingMessage>
Parameters
| Name | Type |
|---|---|
options | string | URL | RequestOptions |
Returns
Promise<IncomingMessage>
delete
▸ Static delete(options?): Promise<IncomingMessage>
Parameters
| Name | Type |
|---|---|
options | string | URL | RequestOptions |
Returns
Promise<IncomingMessage>
get
▸ Static get(options?): Promise<IncomingMessage>
Parameters
| Name | Type |
|---|---|
options | string | URL | RequestOptions |
Returns
Promise<IncomingMessage>
go
▸ Static go(options?): Promise<IncomingMessage>
Parameters
| Name | Type |
|---|---|
options | string | URL | RequestOptions |
Returns
Promise<IncomingMessage>
patch
▸ Static patch(options?): Promise<IncomingMessage>
Parameters
| Name | Type |
|---|---|
options | string | URL | RequestOptions |
Returns
Promise<IncomingMessage>
post
▸ Static post(options?): Promise<IncomingMessage>
Parameters
| Name | Type |
|---|---|
options | string | URL | RequestOptions |
Returns
Promise<IncomingMessage>
put
▸ Static put(options?): Promise<IncomingMessage>
Parameters
| Name | Type |
|---|---|
options | string | URL | RequestOptions |
Returns
Promise<IncomingMessage>
Class: RequestItCookieJar
Hierarchy
CookieJar↳
RequestItCookieJar
Constructors
constructor
• new RequestItCookieJar(store?, options?)
Parameters
| Name | Type |
|---|---|
store? | Store |
options? | Options |
Inherited from
CookieJar.constructor
Properties
store
• store: RequestItStore
Methods
findCookie
▸ findCookie(domain, path, key): Promise<Cookie>
Parameters
| Name | Type |
|---|---|
domain | string |
path | string |
key | string |
Returns
Promise<Cookie>
getCookieString
▸ getCookieString(currentUrl, options?): Promise<string>
Parameters
| Name | Type |
|---|---|
currentUrl | string |
options? | Function | GetCookiesOptions |
Returns
Promise<string>
Overrides
CookieJar.getCookieString
setCookie
▸ setCookie(cookieOrString, currentUrl, options?): Promise<Cookie>
Parameters
| Name | Type |
|---|---|
cookieOrString | string | Cookie |
currentUrl | string |
options? | Function | SetCookieOptions |
Returns
Promise<Cookie>
Overrides
CookieJar.setCookie
fromCookieJar
▸ Static fromCookieJar(cookieJar): RequestItCookieJar
Parameters
| Name | Type |
|---|---|
cookieJar | CookieJar |
Returns
Class: RequestItHeaders
Hierarchy
Map<string,string>↳
RequestItHeaders
Implements
Headers
Constructors
constructor
• new RequestItHeaders(init)
Parameters
| Name | Type |
|---|---|
init | Iterable<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
| Name | Type |
|---|---|
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
| Name | Type |
|---|---|
name | string |
value | string |
Returns
void
Implementation of
Headers.append
set
▸ set(name, value): RequestItHeaders
Parameters
| Name | Type |
|---|---|
name | string |
value | string |
Returns
Implementation of
Headers.set
Overrides
Map.set
Class: RequestItResponse
Implements
Response
Constructors
constructor
• new RequestItResponse(msg)
Parameters
| Name | Type |
|---|---|
msg | IncomingMessage |
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
headers
• get headers(): RequestItHeaders
Returns
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
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
| Name | Type |
|---|---|
domain | string |
path | string |
key | string |
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