manner

5.2.3 • Public • Published

Manner

Build Status NPM Downloads guidelines

Quickly create HTTP services from an object. Manner is framework agnostic and can be plugged to any HTTP server.

  • know the response type: Return buffers, streams, promises, objects or any type of primitives. Manner knows your data type and send its content as fast as possible down the HTTP response.
  • chunk the response content: Response are encoded using the chunk transfer protocol. Manner is memory efficient and can manage a large amount of concurrent request.
  • decode the request data: Manner intelligently decode the data sent through the request and supports any kind of encoding (application/x-www-form-urlencoded, multipart/form-data, json, etc).
  • manage your service status: Manner knows what's going on with your response and send the appropriate status code whenever a method has not been implemented, a media type is not supported, etc.
  • expose methods: Access your service methods independently from any HTTP request. Perfect to decouple your API from its implementation.
  • schema: Apply schema to annotate and validate your service(s) (see test suite)

Usage

Create a web service from an object:

const http = require('http')
const service= require('manner')
 
const db = []
 
const api = service({
  'get': {
    '/': () => 'hello you',
    '/earth': '/world',
    '/:name': (query) => `hello ${query.name}!`
  },
  'post': (query, data) => {
    return db.push(data)
  }
})
 
// HTTP service
http.createServer((req, res) => {
  api(req, res).pipe(res)
})
 
// Programmatic service
api.get('/')
// => hello you
 
api.get('/bob')
// => hello bob!
 
api.get('/earth')
// => hello world!

and programmaticaly add or call routes

 
const api = service({
  'get': () => 'hello world'
})
 
api.get('/:name', query => {
  return `hello ${query.name}!`
})
 
api.get('/bob')
// => hello bob!

Installation

npm install manner --save

NPM

Question

For support, bug reports and or feature requests please make sure to read our community guidelines and use the issue list of this repo and make sure it's not present yet in our reporting checklist.

Contribution

The open source community is very important to us. If you want to participate to this repository, please make sure to read our guidelines before making any pull request. If you have any related project, please let everyone know in our wiki.

License

The MIT License (MIT)

Copyright (c) 2017 Tether Inc

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Package Sidebar

Install

npm i manner

Weekly Downloads

5

Version

5.2.3

License

MIT

Unpacked Size

37.3 kB

Total Files

14

Last publish

Collaborators

  • bredele