3.3.5 • Published 2 months ago

pure-http v3.3.5

Weekly downloads
555
License
MIT
Repository
github
Last release
2 months ago

Installation

$ npm install --save pure-http

Usage

Basic server:

const pureHttp = require('pure-http');

const app = pureHttp();

app.get('/', (req, res) => {
  res.send('Hello world');
});

app.listen(3000);

Existing server:

const http = require('http');
const pureHttp = require('pure-http');

const server = http.createServer();

const app = pureHttp({ server });

app.listen(3000);

Secure server:

const https = require('https');
const pureHttp = require('pure-http');

const server = https.createServer({
  key: ...,
  cert: ...,
});

const app = pureHttp({ server });

app.listen(3000);

Application Options:

  • server: Allows to optionally override the HTTP server instance to be used.

    Default: undefined.

  • onError: A handler when an error is thrown (Deprecated: It has been removed from 3.0.0).

    Default: ((error, req, res) => res.send(error)).

  • onNotFound: A handler when no route definitions were matched (Deprecated: It has been removed from 3.0.0).

    Default: ((req, res) => res.send("Cannot " + req.method + " " + req.url)).

  • views: An object to configuration render function.

    Default: undefined.

    • dir: A directory for the application's views.

    • ext: The default engine extension to use when omitted.

    • engine: Registers the given template engine.

  • Router Options:

    • prefix: Allow append the path before each route.

      Default: undefined.

Router

const { Router } = require('pure-http');

const router = Router();

router.get('/', (req, res) => {
  res.send('Hello world');
});

/* ... */

const pureHttp = require('pure-http');

const app = pureHttp();

app.use('/api', router);

app.listen(3000);

API References

You can read more at API.md.

Benchmarks

Please remember that your application code is most likely the slowest part of your application! Switching from Express to pure-http will (likely) not guarantee the same performance gains.

  • Machine: Ubuntu-s-1vcpu-1gb-sgp1-01, x86-64, Ubuntu 18.04.5 LTS, Intel(R) Xeon(R) CPU E5-2650 v4 @ 2.20GHz, 16GB RAM.
  • Node: v12.18.4
  • Run: Tue, 16 Mar 2021 16:09:01
FrameworkVersionRequests/SecLatency
pure-http (with cache)latest~ 6,34915.11ms
pure-httplatest~ 6,25515.39ms
tinyhttp1.2.17~ 4,94219.44ms
fastify3.14.0~ 3,31029.10ms
express4.17.1~ 2,18843.87ms
  • Machine: Ubuntu-s-1vcpu-1gb-sgp1-01, x86-64, Ubuntu 18.04.5 LTS, Intel(R) Xeon(R) CPU E5-2650 v4 @ 2.20GHz, 16GB RAM.
  • Node: v12.18.4
  • Run: Fri, 13 Nov 2020 21:07:21
FrameworkVersionRequests/SecLatency
pure-http (with cache)2.x.x~ 8,79210.92ms
pure-http2.x.x~ 8,63311.12ms
polka0.5.2~ 7,36413.03ms
express4.17.1~ 3,58826.86ms
fastify3.8.0~ 2,70235.54ms

See more: BENCHMARKS

License

The code in this project is released under the MIT License.

FOSSA Status

3.3.5

2 months ago

3.3.4

5 months ago

3.3.3

10 months ago

3.3.2

12 months ago

3.3.1

3 years ago

3.3.0

3 years ago

3.2.1

3 years ago

3.2.0

3 years ago

3.1.0

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.2.1

3 years ago

2.2.0

3 years ago

2.2.2

3 years ago

2.1.0

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago

0.0.12

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago