@faasjs/request 0.0.2-beta.358 → 0.0.2-beta.362

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +139 -0
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -7,3 +7,142 @@
7
7
  [![NPM Beta Version](https://img.shields.io/npm/v/@faasjs/request/beta.svg)](https://www.npmjs.com/package/@faasjs/request)
8
8
 
9
9
  https://faasjs.com/doc/request.html
10
+
11
+ ## Modules
12
+
13
+ ### Type aliases
14
+
15
+ - [Request](modules.md#request)
16
+ - [RequestOptions](modules.md#requestoptions)
17
+ - [Response](modules.md#response)
18
+
19
+ ### Functions
20
+
21
+ - [querystringify](modules.md#querystringify)
22
+ - [request](modules.md#request)
23
+ - [setMock](modules.md#setmock)
24
+
25
+ ## Type aliases
26
+
27
+ ### Request
28
+
29
+ Ƭ **Request**: `Object`
30
+
31
+ #### Type declaration
32
+
33
+ | Name | Type |
34
+ | :------ | :------ |
35
+ | `body?` | `Object` |
36
+ | `headers?` | `http.OutgoingHttpHeaders` |
37
+ | `host?` | `string` |
38
+ | `method?` | `string` |
39
+ | `path?` | `string` |
40
+ | `query?` | `http.OutgoingHttpHeaders` |
41
+
42
+ ___
43
+
44
+ ### RequestOptions
45
+
46
+ Ƭ **RequestOptions**: `Object`
47
+
48
+ #### Type declaration
49
+
50
+ | Name | Type | Description |
51
+ | :------ | :------ | :------ |
52
+ | `agent?` | `boolean` | - |
53
+ | `auth?` | `string` | HTTP 认证头,格式为 user:password |
54
+ | `body?` | { [key: string]: `any`; } \| `string` | 请求体 |
55
+ | `downloadStream?` | `NodeJS.WritableStream` | 下载流,用于直接将响应内容保存到本地文件,通过 fs.createWriteStream 创建 |
56
+ | `file?` | `string` | 上传文件的完整路径 |
57
+ | `headers?` | `http.OutgoingHttpHeaders` | 请求头 |
58
+ | `method?` | `string` | 请求方法,默认为 GET |
59
+ | `passphrase?` | `string` | - |
60
+ | `pfx?` | `Buffer` | - |
61
+ | `query?` | `Object` | 请求参数,放置于 path 后,若需放置在 body 中,请使用 body 参数 |
62
+ | `timeout?` | `number` | 最长耗时,单位为毫秒 |
63
+ | `parse?` | (`body`: `string`) => `any` | body 解析器,默认为 JSON.parse |
64
+
65
+ ___
66
+
67
+ ### Response
68
+
69
+ Ƭ **Response**<`T`\>: `Object`
70
+
71
+ #### Type parameters
72
+
73
+ | Name | Type |
74
+ | :------ | :------ |
75
+ | `T` | `any` |
76
+
77
+ #### Type declaration
78
+
79
+ | Name | Type |
80
+ | :------ | :------ |
81
+ | `body` | `T` |
82
+ | `headers` | `http.OutgoingHttpHeaders` |
83
+ | `request?` | [`Request`](modules.md#request) |
84
+ | `statusCode?` | `number` |
85
+ | `statusMessage?` | `string` |
86
+
87
+ ## Functions
88
+
89
+ ### querystringify
90
+
91
+ ▸ **querystringify**(`obj`): `string`
92
+
93
+ #### Parameters
94
+
95
+ | Name | Type |
96
+ | :------ | :------ |
97
+ | `obj` | `any` |
98
+
99
+ #### Returns
100
+
101
+ `string`
102
+
103
+ ___
104
+
105
+ ### request
106
+
107
+ ▸ **request**<`T`\>(`url`, `[options={}]?`): `Promise`<[`Response`](modules.md#response)<`T`\>\>
108
+
109
+ 发起网络请求
110
+
111
+ **`url`** https://faasjs.com/doc/request.html
112
+
113
+ #### Type parameters
114
+
115
+ | Name | Type |
116
+ | :------ | :------ |
117
+ | `T` | `any` |
118
+
119
+ #### Parameters
120
+
121
+ | Name | Type | Description |
122
+ | :------ | :------ | :------ |
123
+ | `url` | `string` | 请求路径或完整网址 |
124
+ | `[options={}]` | [`RequestOptions`](modules.md#requestoptions) | 参数和配置 |
125
+
126
+ #### Returns
127
+
128
+ `Promise`<[`Response`](modules.md#response)<`T`\>\>
129
+
130
+ ___
131
+
132
+ ### setMock
133
+
134
+ ▸ **setMock**(`handler`): `void`
135
+
136
+ 设置模拟请求
137
+
138
+ **`example`** setMock(async (url, options) => Promise.resolve({ headers: {}, statusCode: 200, body: { data: 'ok' } }))
139
+
140
+ #### Parameters
141
+
142
+ | Name | Type | Description |
143
+ | :------ | :------ | :------ |
144
+ | `handler` | `Mock` | 模拟函数,若设置为 null 则表示清除模拟函数 |
145
+
146
+ #### Returns
147
+
148
+ `void`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/request",
3
- "version": "0.0.2-beta.358",
3
+ "version": "0.0.2-beta.362",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "dist"
23
23
  ],
24
24
  "peerDependencies": {
25
- "@faasjs/logger": "^0.0.2-beta.358"
25
+ "@faasjs/logger": "^0.0.2-beta.362"
26
26
  },
27
27
  "devDependencies": {
28
28
  "tsup": "*",