@faasjs/request
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. ts const stream = createWriteStream('filepath') await request('https://example.com', { downloadStream: stream }) |
file? | string | Path of uploading a file to the server. ts await request('https://example.com', { file: 'filepath' }) |
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