You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 12, 2019. It is now read-only.
(C) Dan Webb ([email protected]/@danwrong) 2011, Licensed under the MIT-LICENSE
5
5
6
-
An HTTP client library for node.js (0.6.x and up). Hides most of the complexity of creating and using http.Client.
6
+
An HTTP client library for node.js. Hides most of the complexity of creating and using http.Client.
7
7
8
-
**Release 2.x.x** is dedicated to modifying how errors are handled and emitted. Currently errors are being fired as an on 'error' event but as [@ctavan](https://github.com/ctavan) pointed out on [issue #36](https://github.com/danwrong/restler/pull/36) a better approach (and more commonly in vogue now) would be to pass the error obj to the callback.
8
+
See [Version History](https://github.com/danwrong/restler/wiki/Version-History) for changes
9
9
10
-
Ths change will inevitably affect those using older < 0.2.x versions of restler. Those not ready to upgrade yet are encouraged to stay on the 0.2.x version.
10
+
Installing
11
+
----------
11
12
12
-
See [Version History](https://github.com/danwrong/restler/wiki/Version-History) for changes
13
+
```
14
+
npm install restler
15
+
```
16
+
17
+
Running the tests
18
+
-----------------
19
+
20
+
```
21
+
npm test
22
+
```
13
23
14
24
15
25
Features
@@ -18,15 +28,15 @@ Features
18
28
* Easy interface for common operations via http.request
19
29
* Automatic serialization of post data
20
30
* Automatic serialization of query string data
21
-
* Automatic deserialization of XML, JSON and YAML responses to JavaScript objects (if you have js-yaml and/or xml2js in the require path)
31
+
* Automatic deserialization of XML, JSON and YAML responses to JavaScript objects
22
32
* Provide your own deserialization functions for other datatypes
23
33
* Automatic following of redirects
24
34
* Send files with multipart requests
25
35
* Transparently handle SSL (just specify https in the URL)
26
36
* Deals with basic auth for you, just provide username and password options
27
37
* Simple service wrapper that allows you to easily put together REST API libraries
* Transparently handle different content charsets via [iconv-lite](https://github.com/ashtuchkin/iconv-lite)
30
40
31
41
32
42
API
@@ -43,6 +53,7 @@ Basic method to make a request of any type. The function returns a RestRequest o
43
53
*`fail: function(data, response)` - emitted when the request was successful, but 4xx status code returned. Gets passed the response data and the response object as arguments.
44
54
*`error: function(err, response)` - emitted when some errors have occurred (eg. connection aborted, parse, encoding, decoding failed or some other unhandled errors). Gets passed the `Error` object and the response object (when available) as arguments.
45
55
*`abort: function()` - emitted when `request.abort()` is called.
56
+
*`timeout: function(ms)` - when a request takes more than the timeout option eg: {timeout:5000}, the request will be aborted. error and abort events will not be called, instead timeout will be emitted.
46
57
*`2XX`, `3XX`, `4XX`, `5XX: function(data, response)` - emitted for all requests with response codes in the range (eg. `2XX` emitted for 200, 201, 203).
47
58
* <code><i>actual response code</i>: function(data, response)</code> - emitted for every single response code (eg. 404, 201, etc).
48
59
@@ -73,6 +84,10 @@ Create a DELETE request.
73
84
74
85
Create a HEAD request.
75
86
87
+
### patch(url, options)
88
+
89
+
Create a PATCH request.
90
+
76
91
### json(url, data, options)
77
92
78
93
Send json `data` via GET method.
@@ -81,6 +96,9 @@ Send json `data` via GET method.
81
96
82
97
Send json `data` via POST method.
83
98
99
+
### putJson(url, data, options)
100
+
101
+
Send json `data` via PUT method.
84
102
85
103
### Parsers
86
104
@@ -98,45 +116,53 @@ All of these attempt to turn the response into a JavaScript object. In order to
98
116
99
117
### Options
100
118
101
-
*`method` Request method, can be get, post, put, del. Defaults to `"get"`.
119
+
*`method` Request method, can be get, post, put, delete. Defaults to `"get"`.
102
120
*`query` Query string variables as a javascript object, will override the querystring in the URL. Defaults to empty.
103
121
*`data` The data to be added to the body of the request. Can be a string or any object.
104
122
Note that if you want your request body to be JSON with the `Content-Type: application/json`, you need to
105
123
`JSON.stringify` your object first. Otherwise, it will be sent as `application/x-www-form-urlencoded` and encoded accordingly.
106
124
Also you can use `json()` and `postJson()` methods.
107
125
*`parser` A function that will be called on the returned data. Use any of predefined `restler.parsers`. See parsers section below. Defaults to `restler.parsers.auto`.
108
126
*`encoding` The encoding of the request body. Defaults to `"utf8"`.
109
-
*`decoding` The encoding of the response body. For a list of supported values see [Buffers](http://nodejs.org/docs/latest/api/buffers.html#buffers). Additionally accepts `"buffer"` - returns response as `Buffer`. Defaults to `"utf8"`.
127
+
*`decoding` The encoding of the response body. For a list of supported values see [Buffers](http://nodejs.org/api/buffer.html#buffer_buffer). Additionally accepts `"buffer"` - returns response as `Buffer`. Defaults to `"utf8"`.
110
128
*`headers` A hash of HTTP headers to be sent. Defaults to `{ 'Accept': '*/*', 'User-Agent': 'Restler for node.js' }`.
111
129
*`username` Basic auth username. Defaults to empty.
112
130
*`password` Basic auth password. Defaults to empty.
131
+
*`accessToken` OAuth Bearer Token. Defaults to empty.
113
132
*`multipart` If set the data passed will be formated as `multipart/form-encoded`. See multipart example below. Defaults to `false`.
114
133
*`client` A http.Client instance if you want to reuse or implement some kind of connection pooling. Defaults to empty.
115
134
*`followRedirects` If set will recursively follow redirects. Defaults to `true`.
135
+
*`timeout` If set, will emit the timeout event when the response does not return within the said value (in ms)
136
+
*`rejectUnauthorized` If true, the server certificate is verified against the list of supplied CAs. An 'error' event is emitted if verification fails. Verification happens at the connection level, before the HTTP request is sent. Default true.
0 commit comments