# @mafintosh/turbo-http

> Blazing fast low level http server

Latest version **0.1.1** (published 2018-03-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install @mafintosh/turbo-http
pnpm add @mafintosh/turbo-http
yarn add @mafintosh/turbo-http
bun add @mafintosh/turbo-http
```

## 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 | 2018-03-02 |
| First published | 2018-03-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 14.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 992 |
| Author | Mathias Buus |
| Maintainers | mafintosh |

## Links

- npm: https://www.npmjs.com/package/@mafintosh/turbo-http
- Repository: https://github.com/mafintosh/turbo-http
- Issues: https://github.com/mafintosh/turbo-http/issues
- npm.io page: https://npm.io/package/@mafintosh/turbo-http

## Dependencies (2)

- [turbo-net](https://npm.io/package/turbo-net.md) ^1.2.1
- [http-parser-js](https://npm.io/package/http-parser-js.md) ^0.4.10

## Recent versions

- 0.1.1 (latest) — 2018-03-02
- 0.1.0 — 2018-03-02

## README

# turbo-http

A low level http library for Node.js based on [turbo-net](https://github.com/mafintosh/turbo-net)

```
npm install @mafintosh/turbo-http
```

WIP, this module is already *really* fast but there are some HTTP features
missing and easy perf gains to be had :D :D :D

On my laptop I can serve simple hello world payloads at around 100k requests/seconds compared to 10k requests/second using node core.

## Usage

``` js
const turbo = require('@mafintosh/turbo-http')

const server = turbo.createServer(function (req, res) {
  res.setHeader('Content-Length', '11')
  res.write(Buffer.from('hello world'))
})

server.listen(8080)
```

## API

#### `server = turbo.createServer([onrequest])`

Create a new http server. Inherits from [the turbo-net tcp server](https://github.com/mafintosh/turbo-net#server--turbocreateserveroptions-onsocket)

#### `server.on('request', req, res)`

Emitted when a new http request is received.

#### `res.statusCode = code`

Set the http status

#### `res.setHeader(name, value)`

Set a http header

#### `res.write(buf, [length], [callback])`

Write a buffer. When the callback is called, the buffer
has been *completely* flushed to the underlying socket and is safe to
reuse for other purposes

#### `res.writev(buffers, [lengths], [callback])`

Write more that one buffer at once.

#### `res.end([buf], [length], [callback]`)

End the request. Only needed if you do not provide a `Content-Length`.

#### `req.url`

Request url

#### `req.method`

Request method

#### `value = req.getHeader(name)`

Get a request header.

#### `headers = req.getAllHeaders()`

Get all request headers as a map.

#### `req.ondata(buffer, start, length)`

Called when there is data read. If you use the buffer outside of this function
you should copy it.

#### `req.onend()`

Called when the request is fully read.

## Acknowledgements

This project was kindly sponsored by [nearForm](http://nearform.com).

## License

MIT

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