-
Notifications
You must be signed in to change notification settings - Fork 18
/
HTTP.d.ts
101 lines (95 loc) · 2.71 KB
/
HTTP.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* # HTTP
*
* The [[HTTP]] and [[HTTPResponse]] objects are used to run synchronous HTTP requests to communicate with APIs, or just read pages from the web. A full set of custom settings can be passed, and all HTTP methods (GET, POST, PUT, DELETE, etc.) are supported.
*
* ### Example
*
* ```javascript
* var http = HTTP.create(); // create HTTP object
*
* var response = http.request({
* "url": "http://myurl.com/api",
* "method": "POST",
* "data": {
* "key":"value"
* },
* "headers": {
* "HeaderName": "HeaderValue"
* }
* });
*
* if (response.success) {
* var text = response.responseText;
* var data = response.responseData;
* }
* else {
* console.log(response.statusCode);
* console.log(response.error);
* }
* ```
*/
declare class HTTP {
/**
* @param settings An object configuring the request.
*/
request(settings: {
/**
* The absolute HTTP URL for the request.
*/
url: string,
/**
* The HTTP method, like "GET", "POST", etc.
*/
method: string,
/** An object contain key-values to be added as custom headers in the request. */
headers?: { [x: string]: string },
/** Query parameters to merge with the url. Query parameters can also be part of the original url value. */
parameters?: { [x: string]: string },
/** An object containing data to be encoded into the HTTP body of the request. */
data?: { [x: string]: string },
/**
* Format to encode `data` in the body of request.
*/
encoding?: 'json' | 'form',
/** A username to encode for Basic Authentication. */
username?: string,
/** A password to encode for Basic Authentication. */
password?: string
}): HTTPResponse
/**
* Instantiate an `HTTP` object.
*/
static create(): HTTP
}
/**
* # HTTPResponse
*
* HTTPResponse objects are returned by calls to HTTP methods. For usage details, see [[HTTP]] object.
*/
declare class HTTPResponse {
/**
* true/false for whether the request was completed successfully.
*/
success: boolean
/**
* The HTTP status code (like 200, 301, etc.) returned.
*/
statusCode: number
/**
* The raw data returned. Typically an object or array of objects, but exact content varies by server response.
*/
responseData: any
/**
* The data returned as a string format.
*/
responseText: string
/**
* Some responses return additional data that is placed in this field.
*/
otherData: string | undefined
/**
* If an error occurred, a description of the type of error.
*/
error: string | undefined
}