@faasjs/request

License: MITopen in new windowNPM Stable Versionopen in new windowNPM Beta Versionopen in new window

FaasJS's request module.

Install

npm install @faasjs/request

Modules

Type Aliases

Functions

Type Aliases

Request

Ƭ Request: Object

Type declaration

NameType
body?{ [key: string]: any; }
headers?http.OutgoingHttpHeaders
host?string
method?string
path?string
query?http.OutgoingHttpHeaders

RequestOptions

Ƭ RequestOptions: Object

Type declaration

NameTypeDescription
agent?boolean-
auth?stringThe authentication credentials to use for the request. Format: username:password
body?{ [key: string]: any; } | string-
downloadStream?NodeJS.WritableStreamCreate a write stream to download a file. ts const stream = createWriteStream('filepath') await request('https://example.com', { downloadStream: stream })
file?stringPath of uploading a file to the server. ts await request('https://example.com', { file: 'filepath' })
headers?http.OutgoingHttpHeaders-
logger?Logger-
method?stringThe HTTP method to use when making the request. Defaults to GET.
parse?(body: string) => anyBody parser. Defaults to JSON.parse.
passphrase?string-
pfx?Buffer-
query?{ [key: string]: any; }-
timeout?number-

Response

Ƭ Response<T>: Object

Type parameters

NameType
Tany

Type declaration

NameType
bodyT
headershttp.OutgoingHttpHeaders
request?Request
statusCode?number
statusMessage?string

Functions

querystringify

querystringify(obj): string

Parameters

NameType
objany

Returns

string


request

request<T>(url, options?): Promise<Response<T>>

Request

Url

https://faasjs.com/doc/request.html

Type parameters

NameType
Tany

Parameters

NameTypeDescription
urlstringUrl
options?RequestOptionsOptions

Returns

Promise<Response<T>>


setMock

setMock(handler): void

Mock requests

Example

setMock(async (url, options) => Promise.resolve({ headers: {}, statusCode: 200, body: { data: 'ok' } }))

Parameters

NameTypeDescription
handlerMock{function | null} null to disable mock

Returns

void