Skip to content

Commit 8932aaa

Browse files
committed
Merge pull request #68 from jysperm/api-document
更新 API 文档
2 parents 4009d41 + 736cae8 commit 8932aaa

2 files changed

Lines changed: 57 additions & 7 deletions

File tree

API.md

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,15 @@ AV.Cloud.define(name: string, options: object, func: function)
5050
`Request` 上的属性包括:
5151

5252
* `params: object`:客户端发送的参数,当使用 `rpc` 调用时,也可能是 `AV.Object`.
53-
* `user?: AV.User`:客户端所关联的用户(根据客户端发送的 `LC-Session` 头)。
54-
* `meta: {remoteAddress}`:客户端的 IP.
53+
* `currentUser?: AV.User`:客户端所关联的用户(根据客户端发送的 `LC-Session` 头)。
54+
* `user?: AV.User`:同 `currentUser`.
55+
* `meta: {remoteAddress}``meta.remoteAddress` 是客户端的 IP.
56+
* `sessionToken?: string`:客户端发来的 sessionToken(`X-LC-Session` 头)。
5557
5658
`Response` 上的属性包括:
5759
58-
* `success: function(result)`:向客户端发送结果,可以是包括 AV.Object 在内的各种数据类型或数组,客户端解析方式见各 SDK 文档。
59-
* `error: function(err: string)`:向客户端返回一个错误。
60+
* `success: function(result?)`:向客户端发送结果,可以是包括 AV.Object 在内的各种数据类型或数组,客户端解析方式见各 SDK 文档。
61+
* `error: function(err?: string)`:向客户端返回一个错误。
6062

6163
### AV.Cloud.run
6264

@@ -96,7 +98,8 @@ after 类 Hook 的 `func` 签名:`function(request: Request)`。
9698
`Request` 上的属性包括:
9799

98100
* `object: AV.Object`:被操作的对象。
99-
* `user?: AV.User`:发起操作的用户。
101+
* `currentUser?: AV.User`:发起操作的用户。
102+
* `user?: AV.User`:同 `currentUser`.
100103

101104
`Response` 上的属性包括:
102105

@@ -114,7 +117,8 @@ after 类 Hook 的 `func` 签名:`function(request: Request)`。
114117

115118
`Request` 上的属性包括:
116119

117-
* `user: AV.User`:被操作的用户。
120+
* `currentUser: AV.User`:被操作的用户。
121+
* `user: AV.User`:同 `currentUser`.
118122

119123
`Response` 上的属性包括:
120124

@@ -135,6 +139,52 @@ after 类 Hook 的 `func` 签名:`function(request: Request)`。
135139

136140
这些 Hook 需要用 `AV.Cloud.define` 来定义,详见文档 [实时通信概览:云引擎 Hook](https://leancloud.cn/docs/realtime_v2.html#云引擎_Hook)
137141

142+
### AV.Cloud.httpRequest
143+
144+
注意:该 API 已不再维护且可能在之后的版本中去除,请使用 [request](https://www.npmjs.com/package/request) 发起 HTTP 请求。
145+
146+
```javascript
147+
AV.Cloud.httpRequest(options: object);
148+
```
149+
150+
options 的属性包括:
151+
152+
* `url`:被请求的 Url, 例如 `https://api.leancloud.cn/1.1/ping`。
153+
* `success: function(response: Response)`:成功回调,接受一个 HTTP 响应作为参数。
154+
* `error: function(response: Response)`:失败回调,接受一个 HTTP 响应作为参数。
155+
* `method: string`:HTTP 方法,默认为 `GET`。
156+
* `params`:Query String,可以是对象 `{q : 'Sean Plott'}` 也可以是字符串 `q=Sean Plott`
157+
* `headers: object`:HTTP 头,例如 `{'Content-Type': 'application/json'}`
158+
* `body: object`:HTTP 请求正文,默认使用 urlencode 编码,如果指定了 `Content-Type``application/json` 则发送 JSON 格式的正文;不适用于 `GET``HEAD` 请求。
159+
* `timeout: number`:超时时间,单位秒,默认 `10000`
160+
161+
Response 的属性包括:
162+
163+
* `status: number`:HTTP 响应状态码。
164+
* `headers: object`:HTTP 响应头。
165+
* `text: string`:HTTP 响应正文。
166+
* `buffer: Buffer`:HTTP 响应正文。
167+
* `data` 解析后的 HTTP 响应正文,例如对于 `Content-Type``application/json` 时,会将响应正文解析为一个对象。
168+
169+
示例:
170+
171+
```javascript
172+
AV.Cloud.httpRequest({
173+
method: 'POST',
174+
url: 'http://www.example.com/create_post',
175+
body: {
176+
title: 'Vote for Pedro',
177+
body: 'If you vote for Pedro, your wildest dreams will come true'
178+
},
179+
success: function(httpResponse) {
180+
console.log(httpResponse.text);
181+
},
182+
error: function(httpResponse) {
183+
console.error('Request failed with response code ' + httpResponse.status);
184+
}
185+
});
186+
```
187+
138188
## Middlewares
139189
140190
### cookie-session

lib/leanengine.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ if (!AV._old_Cloud) {
4747

4848
AV.Cloud = function() {
4949
if (!defaultMiddleware) {
50-
console.trace('Use AV.Cloud as a middleware is deprecated, use AV.express() instead');
50+
console.error('Use AV.Cloud as a middleware is deprecated, use AV.express() instead');
5151
defaultMiddleware = AV.express();
5252
}
5353

0 commit comments

Comments
 (0)