# test-http-server

> Decorate webservers with easy to use client request methods

Latest version **0.3.2** (published 2013-05-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install test-http-server
pnpm add test-http-server
yarn add test-http-server
bun add test-http-server
```

## 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.3.2 |
| Published | 2013-05-20 |
| First published | 2013-05-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.8.4 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Tim Kuijsten |
| Maintainers | timkuijsten |
| Keywords | http, test, server |

## Links

- npm: https://www.npmjs.com/package/test-http-server
- Repository: https://github.com/timkuijsten/node-test-http-server
- Issues: https://github.com/timkuijsten/node-test-http-server/issues
- npm.io page: https://npm.io/package/test-http-server

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 0.3.2 (latest) — 2013-05-20
- 0.3.1 — 2013-05-20
- 0.3.0 — 2013-05-20
- 0.2.0 — 2013-05-15
- 0.1.0 — 2013-05-15

## README

# test-http-server

Decorate webservers with easy to use client request methods.

## Usage

    // setup and start a simple echo server
    var server = http.createServer();
    server.on('request', function(req, res) { req.pipe(res); });

    server.listen(1234, '127.0.0.1', function() {
      var data = 'foo';

      // decorate server with .get(), .post(), .path() etc.
      require('test-http-server')(server);

      // now get, head, post, put, patch, del are available
      // on server

      // post some data and expect it to be echo'd back
      server.post('/some/url', data, function(response, body) {
        // post request is done and body is 'foo'
      });
    });

## Installation

    $ npm install test-http-server

## API

### testHttpServer(server)
* server http.Server

Decorates the provided http server with with easy to use client request methods.

### server.setBasicAuth(username, password)
* username String
* password String

Set credentials to be used with each request.

### server.get(url, [headers], [cb])
* url String
* headers Object
* cb Function

Do a get request. Callback is called with the response and the body.

### server.head(url, [headers], [cb])
* url String
* headers Object
* cb Function

Do a head request. Callback is called with the response and the body.

### server.post(url, data, [headers], [cb])
* url String
* data {String|Object}
* headers Object
* cb Function

Do a post request. If data is an object, the default content-type will be application/json. Callback is called with the response and the body.

### server.put(url, data, [headers], [cb])
* url String
* data {String|Object}
* headers Object
* cb Function

Do a put request. If data is an object, the default content-type will be application/json. Callback is called with the response and the body.

### server.patch(url, data, [headers], [cb])
* url String
* data {String|Object}
* headers Object
* cb Function

Do a patch request. If data is an object, the default content-type will be application/json. Callback is called with the response and the body.

### server.del(url, [headers], [cb])
* url String
* headers Object
* cb Function

Do a delete request. Callback is called with the response and the body.

## License

MIT, see LICENSE

## Bugs

See <https://github.com/timkuijsten/node-test-http-server/issues>.

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