Skip to content

Commit

Permalink
Merge pull request #39 from jkyberneees/drop-turbo-http-support
Browse files Browse the repository at this point in the history
drop support for turbo-http
  • Loading branch information
jkyberneees authored May 19, 2019
2 parents 010a54e + 75f013f commit 809788a
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 167 deletions.
32 changes: 6 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
[![Build Status](https://travis-ci.org/jkyberneees/ana.svg?branch=master)](https://travis-ci.org/jkyberneees/ana)
[![NPM version](https://img.shields.io/npm/v/restana.svg?style=flat)](https://www.npmjs.com/package/restana)
Blazing fast, tiny and minimalist *connect-like* web framework for building REST micro-services.
[> Check how much faster!](https://github.com/the-benchmarker/web-frameworks#full-table-1)
> Uses 'find-my-way' router: https://www.npmjs.com/package/find-my-way
What else? *[Building ultra-fast REST APIs with Node.js (restana vs express vs fastify)](https://medium.com/@kyberneees/building-ultra-fast-rest-apis-with-node-js-and-restana-1d65b0d524b7)*
Expand Down Expand Up @@ -245,29 +246,6 @@ const server = http.createServer(service.callback())
//...
```

## turbo-http integration
What is turbo-http? Checkout: https://www.npmjs.com/package/turbo-http
Using `turbo-http` in restana:
```bash
npm i turbo-http
```
```js
// ATTENTION: The performance of the service below can blow your mind ;)
const server = require('restana/libs/turbo-http')
const service = require('restana')({
server
})

service.get('/hi', (req, res) => {
res.send({
msg: 'Hello World!'
})
})

service.start()
```
> NOTE: When using `turbo-http`, the node.js `cluster` module can't be used!
## Performance comparison (framework overhead)
> measurements below refers to version 2.4
Expand All @@ -278,7 +256,6 @@ Laptop: MacBook Pro 2016, 2,7 GHz Intel Core i7, 16 GB 2133 MHz LPDDR3
wrk -t8 -c8 -d30s http://localhost:3000/hi
```
### String response ('Hello World!')
* **restana-turbo-http**: Requests/sec 57708.05
* **restana**: Requests/sec 46314.39
* **restana-cluster**: Requests/sec 70979.80
* fastify: Requests/sec 36873.05
Expand All @@ -288,7 +265,6 @@ wrk -t8 -c8 -d30s http://localhost:3000/hi
* express: Requests/sec 16812.15

### JSON response ({msg: 'Hello World!'})
* **restana-turbo-http**: Requests/sec 53544.21
* **restana**: Requests/sec 39363.91
* fastify: Requests/sec 33600.85
* restify: Requests/sec 29490.79
Expand All @@ -300,4 +276,8 @@ wrk -t8 -c8 -d30s http://localhost:3000/hi
You can also checkout `restana` performance index on the ***"Which is the fastest"*** project: https://github.com/the-benchmarker/web-frameworks#full-table-1

## Using this project? Let us know 🚀
https://goo.gl/forms/qlBwrf5raqfQwteH3
https://goo.gl/forms/qlBwrf5raqfQwteH3

## Breacking changes
### 3.x:
- Support for `turbo-http` library was dropped.
15 changes: 0 additions & 15 deletions demos/turbo-http-body-parser.js

This file was deleted.

12 changes: 9 additions & 3 deletions libs/response-extensions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const CONTENT_TYPE_HEADER = 'content-type'

/**
* The friendly 'res.send' method
* No comments needed ;)
Expand Down Expand Up @@ -38,11 +40,15 @@ module.exports.send = (options, req, res) => (data = 200, code = 200, headers =
data,
code
}
if (options.disableResponseEvent !== true) { res.emit('response', params) }
if (options.disableResponseEvent !== true) {
res.emit('response', params)
}

if (typeof data === 'object' && data instanceof Buffer === false) {
// transparently setting the 'content-type' header if JSON
res.setHeader('content-type', 'application/json')
if (!res.hasHeader(CONTENT_TYPE_HEADER)) {
// transparently setting the 'content-type' header if JSON
res.setHeader(CONTENT_TYPE_HEADER, 'application/json')
}
params.data = JSON.stringify(params.data)
}

Expand Down
37 changes: 0 additions & 37 deletions libs/turbo-http.js

This file was deleted.

47 changes: 1 addition & 46 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "restana",
"version": "2.14.0",
"version": "3.0.0",
"description": "Super fast and minimalist web framework for building REST micro-services.",
"main": "index.js",
"types": "index.d.ts",
Expand Down Expand Up @@ -57,7 +57,6 @@
"restify": "^7.7.0",
"standard": "^12.0.1",
"supertest": "^3.4.2",
"turbo-http": "^0.3.2",
"winston": "^2.4.4"
}
}
12 changes: 0 additions & 12 deletions performance/turbo-http-minimal-json.js

This file was deleted.

10 changes: 0 additions & 10 deletions performance/turbo-http-minimal.js

This file was deleted.

20 changes: 4 additions & 16 deletions tests.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/* global describe, it */
const expect = require('chai').expect
const request = require('supertest')
const http = require('http')

describe('Restana Web Framework - Smoke', () => {
let server
const service = require('./index')({ server: require('./libs/turbo-http') })
const service = require('./index')({
server: http.createServer()
})

it('service options are exposed through getServiceOptions', (done) => {
expect(typeof service.getConfigOptions().server).to.equal('object')
Expand Down Expand Up @@ -49,14 +52,6 @@ describe('Restana Web Framework - Smoke', () => {
throw new Error('error')
})

service.get('/turbo-http-headers', (req, res) => {
if (!req.headers || !req.headers['test'] || req.headers['test'] !== '123') {
res.send(500)
} else {
res.send(200)
}
})

service.get('/handler-override', (req, res) => res.send('1'))
service.get('/handler-override', (req, res) => res.send('2'))

Expand Down Expand Up @@ -116,13 +111,6 @@ describe('Restana Web Framework - Smoke', () => {
.expect(404)
})

it('should have req.headers as plain object when work with turbo-http', async () => {
await request(server)
.get('/turbo-http-headers')
.set('test', '123')
.expect(200)
})

it('should receive service routing keys array - i.e: ["[GET]/pets/:id"]', async () => {
expect(service.routes().includes('[GET]/pets/:id')).to.equal(true)
})
Expand Down

0 comments on commit 809788a

Please sign in to comment.