@faasjs/request 0.0.2-beta.360 → 0.0.2-beta.364

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