# simple-request

> Simple wrapper of the native HTTP client

Latest version **0.1.1** (published 2013-06-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install simple-request
pnpm add simple-request
yarn add simple-request
bun add simple-request
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2013-06-04 |
| First published | 2013-04-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.8.18 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | John Manero |
| Maintainers | jmanero |

## Links

- npm: https://www.npmjs.com/package/simple-request
- Repository: https://github.com/jmanero/simple-request
- Issues: https://github.com/jmanero/simple-request/issues
- npm.io page: https://npm.io/package/simple-request

## Recent versions

- 0.1.1 (latest) — 2013-06-04
- 0.1.0 — 2013-04-23
- 0.0.1 — 2013-04-05

## README

Simple Request
==============
A _really_ simple wrapper for native HTTP[S] clients.

This module encapsulates the boiler-plate task of aggregating chunked responses
from HTTP servers. It has a few simple helpers to stringify and parse JSON bodies,
set several required headers if not present, and wait automatically for a
`100 CONTINUE` head to send data if the `expect` parameter is passed in a request
method's `options` hash.

### Constructor
`var client = Request(params)`

#### Params (optional)
 * `protocol` Anything that matches Node.JS's [HTTP API](http://nodejs.org/docs/v0.8.19/api/http.html), specifically, [HTTP.request](http://nodejs.org/docs/v0.8.19/api/http.html#http_http_request_options_callback) Default is `HTTP`
 * `host` A default target for the client
 * `port` A default port for the target

### Request
`client.request(options, body, callback)`

#### Options
 * Anything supported by [HTTP.request](http://nodejs.org/docs/v0.8.19/api/http.html#http_http_request_options_callback)
 * `expect` Set the `Expect: 100-Continue` header, and don't send pay-load until the 100 head is received

#### Body
Must be an object that can be consumed by `JSON.stringify` or casted to a
string, or `null`

#### Callback
`function(error, response)` will be passed error objects, or the protocol's
response object. If the response contained a pay-load, it will be in string-form
in `response.data`. If the response `Content-Type` was `application/json[; ...]`,
the parsed object will be in `response.body`. In this case, an invalid JSON pay-load
will cause an error to be returned.

### Usage

    var Client = require('simple-request');
    var c = new Client(); // Default HTTP
    
    // For HTTPS, or an other interface that implements the same API:
    // var HTTPS = require('https');
    // var c = new Client(HTTPS);
    
    c.request({
        hostname : "google.com",
        port : 80,
        method : "GET",
        headers : {
            'x-foo-bar' : "Hello World"
        },
        path : "/search?q=define+chunked"
    }, function(err, res) {
        if(err) {
           console.log("Oh No");
           return;
       }
       
       console.log(res.data); // The response body is returned in the data attribute
       // If response header "Content-Type: application/json[; encoding=...]" is set,
       // res.body will contain the parsed object. 
    });
        

### Helper Methods
 * `get(path, [options, ]callback)`
 * `post(path, body, [options, ]callback)`
 * `put(path, body, [options, ]callback)`
 * `delete(path, [options, ]callback)`

## License
Copyright (c) 2013 John Manero, Dynamic Network Services Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

---
_Source: https://npm.io/package/simple-request · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
