@faasjs/request

[![License: MIT](https://img.shields.io/npm/l/@faasjs/request.svg)](https://github.com/faasjs/faasjs/blob/main/packages/faasjs/request/LICENSE) [![NPM Stable Version](https://img.shields.io/npm/v/@faasjs/request/stable.svg)](https://www.npmjs.com/package/

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
@faasjs/request
8310.0.2-beta.419a day ago3 years agoMinified + gzip package size for @faasjs/request in KB

Readme

@faasjs/request
License: MIT NPM Stable Version NPM Beta Version
FaasJS's request module.

Install

npm install @faasjs/request

Modules

Type Aliases

Functions

Type Aliases

Request

Ƭ Request: Object

Type declaration

| Name | Type | | :------ | :------ | | body? | { [key: string]: any; } | | headers? | http.OutgoingHttpHeaders | | host? | string | | method? | string | | path? | string | | query? | http.OutgoingHttpHeaders |

RequestOptions

Ƭ RequestOptions: Object

Type declaration

| Name | Type | Description | | :------ | :------ | :------ | | agent? | boolean | - | | auth? | string | The authentication credentials to use for the request. Format: username:password | | body? | { [key: string]: any; } \| string | - | | downloadStream? | NodeJS.WritableStream | Create a write stream to download a file. | | file? | string | Path of uploading a file to the server. | | headers? | http.OutgoingHttpHeaders | - | | logger? | Logger | - | | method? | string | The HTTP method to use when making the request. Defaults to GET. | | parse? | (body: string) => any | Body parser. Defaults to JSON.parse. | | passphrase? | string | - | | pfx? | Buffer | - | | query? | { [key: string]: any; } | - | | timeout? | number | - |

Response

Ƭ Response<T\>: Object

Type parameters

| Name | Type | | :------ | :------ | | T | any |

Type declaration

| Name | Type | | :------ | :------ | | body | T | | headers | http.OutgoingHttpHeaders | | request? | Request
| | statusCode? | number | | statusMessage? | string |

Functions

querystringify

querystringify(obj): string

Parameters

| Name | Type | | :------ | :------ | | obj | any |

Returns

string

request

request<T\>(url, options?): Promise<Response
<T\>\>
Request
Url
https://faasjs.com/doc/request.html

Type parameters

| Name | Type | | :------ | :------ | | T | any |

Parameters

| Name | Type | Description | | :------ | :------ | :------ | | url | string | Url | | options? | RequestOptions | Options |

Returns

Promise<Response<T\>\>

setMock

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

Parameters

| Name | Type | Description | | :------ | :------ | :------ | | handler | Mock | {function \| null} null to disable mock |

Returns

void