Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 31 lines (23 sloc) 1.149 kb
758f598 @mikeal Initial commit. Request package.
mikeal authored
1 # Request -- Simplified HTTP request method
2
12a4cb8 @mikeal Matching node documentation style.
mikeal authored
3 ## Install
758f598 @mikeal Initial commit. Request package.
mikeal authored
4
5 <pre>
6 npm install request
7 </pre>
8
12a4cb8 @mikeal Matching node documentation style.
mikeal authored
9 ## Super simple to use
758f598 @mikeal Initial commit. Request package.
mikeal authored
10
12a4cb8 @mikeal Matching node documentation style.
mikeal authored
11 #### request(options, callback)
758f598 @mikeal Initial commit. Request package.
mikeal authored
12
12a4cb8 @mikeal Matching node documentation style.
mikeal authored
13 The first argument is an options object. The only required option is uri, all others are optional.
14
15 * `'uri'` - fully qualified uri or a parsed url object from url.parse()
16 * `'method'` - http method, defaults to GET
17 * `'headers'` - http headers, defaults to {}
18 * `'body'` - entity body for POST and PUT requests
19 * `'client'` - existing http client object (when undefined a new one will be created and assigned to this property so you can keep around a reference to it if you would like use keep-alive on later request)
20
21 The callback argument gets 3 arguments. The first is an error when applicable (usually from the http.Client option not the http.ClientRequest object). The second in an http.ClientResponse object. The third is the response body buffer.
22
23 Example:
104cc94 @mikeal Removing unnecessary markup.
mikeal authored
24 <pre>
758f598 @mikeal Initial commit. Request package.
mikeal authored
25 var request = require('request');
26 request({uri:'http://www.google.com'}, function (error, response, body) {
27 if (!error && response.statusCode == 200) {
28 sys.puts(body) // Print the google web page.
29 }
30 })
12a4cb8 @mikeal Matching node documentation style.
mikeal authored
31 </pre>
Something went wrong with that request. Please try again.