simple-get
Simplest way to make http get requests
features
This module is the lightest possible wrapper on top of node.js http, but supporting these essential features:
follows redirects
automatically handles gzip/deflate responses
supports HTTPS
supports specifying a timeout
supports convenience
urlkey so there's no need to useurl.parseon the url when specifying optionscomposes well with npm packages for features like cookies, proxies, form data, & OAuth
All this in < 100 lines of code.
install
npm install simple-getusage
Note, all these examples also work in the browser with browserify.
simple GET request
Doesn't get easier than this:
even simpler GET request
If you just want the data, and don't want to deal with streams:
POST, PUT, PATCH, HEAD, DELETE support
For POST, call get.post or use option { method: 'POST' }.
A more complex example:
JSON
You can serialize/deserialize request and response with JSON:
Timeout
You can set a timeout (in milliseconds) on the request with the timeout option. If the request takes longer than timeout to complete, then the entire request will fail with an Error.
One Quick Tip
It's a good idea to set the 'user-agent' header so the provider can more easily see how their resource is used.
Proxies
You can use the tunnel module with the agent option to work with proxies:
Cookies
You can use the cookie module to include cookies in a request:
Form data
You can use the form-data module to create POST request with form data:
Or, include application/x-www-form-urlencoded form data manually:
application/x-www-form-urlencoded form data manually:Specifically disallowing redirects
Basic Auth
OAuth
You can use the oauth-1.0a module to create a signed OAuth request:
Throttle requests
You can use limiter to throttle requests. This is useful when calling an API that is rate limited.
license
MIT. Copyright (c) Feross Aboukhadijeh.
Last updated