GithubHelp home page GithubHelp logo

turbo-http's Introduction

turbo-http

A low level http library for Node.js based on turbo-net

npm install 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

const turbo = require('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

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.

License

MIT

turbo-http's People

Contributors

mafintosh avatar millette avatar

Watchers

James Cloos avatar Richard M Wan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.