https://github.com/rfrench/curler
A native c++ node.js module for asynchronous http requests via libcurl.
https://github.com/rfrench/curler
Last synced: over 1 year ago
JSON representation
A native c++ node.js module for asynchronous http requests via libcurl.
- Host: GitHub
- URL: https://github.com/rfrench/curler
- Owner: rfrench
- License: mit
- Created: 2012-05-08T18:23:26.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2017-11-03T02:44:48.000Z (over 8 years ago)
- Last Synced: 2025-04-12T02:03:52.170Z (over 1 year ago)
- Language: C++
- Size: 15.6 KB
- Stars: 19
- Watchers: 3
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# curler
A native c++ node.js module for asynchronous http requests via libcurl.
## Install
$ npm install curler
## request(options, callback[err, res, bodyData])
### Options
- `url`: request url. (required)
- `method`: HTTP method type. Defaults to `GET`. (can be anything)
- `headers`: Optional JSON key/value array of the request headers.
- `userAgent`: Optional custom user agent.
- `proxy`: Optional proxy support. (i.e. http://proxy.example.com:80)
- `data`: Optional request body data.
- `timeout`: Total request timeout (connection/response) in milliseconds.
- `connectionTimeout`: Connection timeout in milliseconds.
## Examples
### GET request
``` js
var curler = require("curler").Curler;
var curl = new curler();
var options = {
method: "GET",
url: 'http://www.google.com'
};
var startDate = Date.now();
curl.request(options, function(err, res, bodyData) {
var duration = (Date.now() - startDate);
if (err) {
console.log(err);
}
else {
console.log('statusCode: %s', res.statusCode);
console.log('bodyData: %s', bodyData);
}
console.log("curler (libcurl) performed http request in %s ms. dnsTime: %s, connectTime: %s, preTransferTime: %s, startTransferTime: %s, totalTime: %s", duration, res.dnsTime, res.connectTime, res.preTransferTime, res.startTransferTime, res.totalTime);
});
```
### POST request (body data)
``` js
var curler = require("curler").Curler;
var curl = new curler();
var data = JSON.stringify({ hello: 'world' });
var options = {
method: "POST",
url: 'http://www.example.com/',
userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3',
headers: {
'Content-Type': 'application/json',
'Connection': 'Keep-Alive'
},
data: data,
timeout: 5000,
connectionTimeout: 5000
};
var startDate = Date.now();
curl.request(options, function(err, res, bodyData) {
var duration = (Date.now() - startDate);
if (err) {
console.log(err);
}
else {
console.log('statusCode: %s', res.statusCode);
console.log('bodyData: %s', bodyData);
}
console.log("curler (libcurl) performed http request in %s ms. dnsTime: %s, connectTime: %s, preTransferTime: %s, startTransferTime: %s, totalTime: %s", duration, res.dnsTime, res.connectTime, res.preTransferTime, res.startTransferTime, res.totalTime);
});
```
## TODO
- Allow Expect: 100-Continue to be configurable, rather than always off
- Load a queue of curl handles when the module loads (ghetto connection pooling). Need a deconstructor in curler.cc that works first!