Giter Club home page Giter Club logo

agnostic's Introduction

agnostic NPM Module

A library that allows other projects to be agnostic of particular http server implementation.

Linux Build MacOS Build Windows Build

Coverage Status Dependency Status bitHound Overall Score

Notice of change of ownership: Starting version 1.0.0 this package has changed it's owner and goals. Old version (0.0.0) is still available on npm via npm install [email protected] or on github. Thank you.

node / libs express restify hapi http
v0.12 3.x, 4.x 2.x, 3.x, 4.x 8.x, 9.x, 10.x
io.js 3.x, 4.x 2.x, 3.x, 4.x 8.x, 9.x, 10.x
v4 3.x, 4.x 2.x, 3.x, 4.x 8.x, 9.x, 10.x, 11.x, 12.x, 13.x, 14.x, 15.x
v5 3.x, 4.x 2.x, 3.x, 4.x 8.x, 9.x, 10.x, 11.x, 12.x, 13.x, 14.x, 15.x
v6 3.x, 4.x 2.x, 3.x, 4.x 8.x, 9.x, 10.x, 11.x, 12.x, 13.x, 14.x, 15.x

Install

npm install --save agnostic

Example

Your Library

var agnostic = require('agnostic');

module.exports = agnostic(myRequestHandler);

/**
 * Does cool things
 *
 * @param {EventEmitter} request - request object, mimicking IncomingMessage
 * @param {Function} respond - callback to respond to the request
 */
function myRequestHandler(request, respond)
{
  // do cool things
  // `request.body` - parsed request body
  // `request.query` - parsed query string
  // `respond` is a function with the following signature:
  // `respond([code], [content[, options]]);`
  respond(200, 'Received hit to ' + request.url, {headers: {'X-Powered-By': 'AllCoolThings'}});
}

Express express

var express = require('express');
var coolLib = require('above-cool-lib');

var app = express();

app.all('/my-endpoint', coolLib);

// start the server
app.listen(1337);

Restify restify

var restify = require('restify');
var coolLib = require('above-cool-lib');

var server = restify.createServer();

server.get('/my-endpoint', coolLib);
server.post('/my-endpoint', coolLib);

// start the server
server.listen(1337);

Hapi hapi

var Hapi = require('hapi');
var coolLib = require('above-cool-lib');

var server = new Hapi.Server();

// setup hapi server
server.connection({ port: 1337 });

server.route({
  method : ['GET', 'POST'], // Hapi uses GET handler for HEAD requests
  path   : '/my-endpoint',
  handler: coolLib
});

// start the server
server.start();

http http

  var http    = require('http');
  var coolLib = require('above-cool-lib');

  server = http.createServer(coolLib);

  // start the server
  server.listen(1337);

Want to Know More?

More examples can be found in test folder.

Or open an issue with questions and/or suggestions.

License

Agnostic is released under the MIT license.

agnostic's People

Contributors

alexindigo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

omgimalexis

agnostic's Issues

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.