# hammock

> Node.js mock / polyfill http object library for http req / res

Latest version **3.0.1** (published 2019-05-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install hammock
pnpm add hammock
yarn add hammock
bun add hammock
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.1 |
| Published | 2019-05-03 |
| First published | 2013-02-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 16.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 21 |
| Author | Tommy Messbauer |
| Maintainers | raynos, tommydudebreaux |
| Keywords | node, mock, http, request, response, polyfill |

## Links

- npm: https://www.npmjs.com/package/hammock
- Repository: https://github.com/doanythingfordethklok/hammock
- Homepage: https://github.com/doanythingfordethklok/hammock#readme
- Issues: https://github.com/doanythingfordethklok/hammock/issues
- npm.io page: https://npm.io/package/hammock

## Dependencies (2)

- [cookies](https://npm.io/package/cookies.md) 0.7.3
- [readable-stream](https://npm.io/package/readable-stream.md) 2.3.3

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 3.0.1 (latest) — 2019-05-03
- 3.0.0 — 2019-04-18
- 2.2.0 — 2018-01-26
- 2.1.0 — 2017-11-15
- 2.0.1 — 2016-09-27
- 2.0.0 — 2016-09-24
- 1.1.2 — 2016-09-24
- 1.1.1 — 2016-09-23
- 1.1.0 — 2015-12-22
- 1.0.2 — 2015-03-06
- 1.0.1 — 2015-03-06
- 1.0.0 — 2015-01-22
- 0.1.10 — 2015-01-06
- 0.1.9 — 2014-07-08
- 0.1.7 — 2014-06-09
- … 13 more at https://npm.io/package/hammock/versions

## README

# hammock.  [![Build Status](https://travis-ci.org/doanythingfordethklok/hammock.svg?branch=master)](https://travis-ci.org/doanythingfordethklok/hammock)

Node.js mock / polyfill http object library for http req / res.  

# Motivation

Polyfill req / res for testing w/o http or for code generation from an existing site. Since the purpose of this lib is mock req/res for testing, you probably want this as a dev dependency. I think I've used it in a production app for something like SSR or something, but it was unusual!!! 

# Install Node (0.10+)
This includes new releases (e.g. 0.10, 0.11, 0.12, iojs, 4, 5, 6, 7, 8, 9, 10, 11)

```
npm install hammock --save-dev

OR 

yarn add hammock --dev
```

# Install - Node (0.8 compatibility)

Hammock v3 breaks backwards compatibility for node 0.8 which
will not affect the vast majority of users. For those still
using 0.8, use major version 2.

```
npm install hammock@^2.2.0 --save-dev

OR 

yarn add hammock@v2.2.0 --dev
```


# Example


```js
/* Should consider migrating to a factory so that people don't have to guess whether to use new or not */
var MockRequest = require('hammock').Request,
    MockResponse = require('hammock').Response;

/* Most This is most helpful for GET requests.  In future, it would be nice to polyfill body parsing events. */
var req = new MockRequest({
        url: '/foo',
        headers: { host: 'localhost', bar: 'baz' },
        method: 'GET'
    }),
    res = new MockResponse();

res.on('end', function(err, data) {
     console.log(data.statusCode);
     console.log(util.inspect(data.headers));
     console.log(data.body);
});

/* Using pipeline-router / director syntax here, but this should be simple with express. */
var router = RouterFactory.create({ /* options */ });
router.dispatch(req, res);

```

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