# http-infer

> Convert the returns of a route to a http response

Latest version **0.0.1** (published 2016-12-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install http-infer
pnpm add http-infer
yarn add http-infer
bun add http-infer
```

## 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.0.1 |
| Published | 2016-12-05 |
| First published | 2016-12-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | thomas-jensen |

## Links

- npm: https://www.npmjs.com/package/http-infer
- Repository: https://github.com/srcagency/http-infer
- Homepage: https://github.com/srcagency/http-infer#readme
- Issues: https://github.com/srcagency/http-infer/issues
- npm.io page: https://npm.io/package/http-infer

## Recent versions

- 0.0.1 (latest) — 2016-12-05

## README

# http-infer

Convert a simple return value from a route function into a description of a
http response. The response is of the format accepted by
[http-tell](https://github.com/srcagency/http-tell).


```js
infer(value) -> {
	// headers
	code,
	message,
	headers,

	// body
	json,
	raw,
};
```

Return values are interpreted as:

- `undefined` will by translated into a `204` (`No content`) http response
- Any object with a `code` property will be thought to be a valid response
  definition and is therefore returned as is
- Any other value will be wrapped as `{ code: 200, json: value }`

## Examples

```js
var infer = require('http-infer');
var tell = require('http-tell');

http.createServer(function( request, response ){
	tell(response, infer())
		.then(() => console.log('Completed a 200 request without content'));
})
	.listen(8000);
```

Streaming JSON:

```js
var infer = require('http-infer');
var tell = require('http-tell');
var pull = require('pull-stream');

http.createServer(function( request, response ){
	tell(response, infer(pull.values([ 'a', 'b', 'c' ])))
		.then(() => console.log('Streamed all values to the client'));
})
	.listen(8000);
```

"Pass through" objects with a `code`

```js
var infer = require('http-infer');
var tell = require('http-tell');

http.createServer(function( request, response ){
	tell(response, infer({
		code: 400,
		json: { error: 'Something bad' },
	}))
		.then(() => console.log('Send a 400 response'));
})
	.listen(8000);
```

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