https://github.com/bendrucker/micro-req
[Deprecated] Tiny (bytes and API) http interface for Node and the browser
https://github.com/bendrucker/micro-req
Last synced: 10 months ago
JSON representation
[Deprecated] Tiny (bytes and API) http interface for Node and the browser
- Host: GitHub
- URL: https://github.com/bendrucker/micro-req
- Owner: bendrucker
- License: mit
- Created: 2015-07-17T12:31:40.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2018-11-13T19:33:46.000Z (over 7 years ago)
- Last Synced: 2025-09-11T16:53:06.913Z (11 months ago)
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# [deprecated] micro-req [](https://travis-ci.org/bendrucker/micro-req)
**Deprecated, use [xhr-request](https://github.com/jam3/xhr-request) instead. Same goal, even smaller API!**
> Tiny (bytes and API) http interface for Node and the browser
At 3.5k minified and gzipped, you get Node-compatible code without the ~50kb most Node HTTP libraries weigh when browserified. The byte savings mostly comes from abandoning support for streaming HTTP, Buffers, and other features.
## Install
```
$ npm install --save micro-req
```
## Usage
```js
var request = require('micro-req')
request('http://apple.com', console.log)
//=> {body: '...', statusCode: 200, headers: {...}}
```
## API
#### `request(url, [options], callback)` -> `undefined`
##### url
*Required*
Type: `string`
The URL to request.
##### options
###### method
Type: `string`
Default: `'GET'`
The HTTP method to use to perform the request.
###### headers
Type: `object`
Default: `{}`
HTTP headers.
###### json
Type: `boolean`
Default: `false`
When `true`, the `Accept` and `Content-Type` headers will be sent as `'application/json'`, the request body will be passed to `JSON.stringify` and the response will be parsed with `JSON.parse`.
###### body
Type: `any`
The request body to transmit.
###### timeout
Type: `number`
Default: `0`
A request timeout to apply in milliseconds. Timeouts are considered an error.
#### callback
*Required*
Type: `function`
Arguments: `err, response`
The `response` contains:
###### body
Type: `any`
The parsed response body.
###### statusCode
Type: `number`
The HTTP response code.
###### headers
Type: `object`
The HTTP response headers.
---
#### `request.get(url, [options], callback)`
#### `request.post(url, [options], callback)`
#### `request.put(url, [options], callback)`
#### `request.patch(url, [options], callback)`
#### `request.head(url, [options], callback)`
#### `request.delete(url, [options], callback)`
Convenience methods instead of setting `options.method` directly.
## License
MIT © [Ben Drucker](http://bendrucker.me)