Giter Club home page Giter Club logo

falcor-hapi's Introduction

falcor-hapi

Server middleware for falcor-hapi

Working usage example in falcor-hapi-demo repo

Usage

Minimalistic example

var FalcorServer = require('falcor-hapi');
var Hapi = require('hapi');
var TestRouter = <your router here>;

var app = new Hapi.Server();
app.connection({
    host: "localhost",
    port: 9090
});

app.route({
    method: ['GET', 'POST'],
    path: '/model.json',
    handler: FalcorServer.dataSourceRoute(function(req, res) {
        return new TestRouter();
    })
});
app.start();

Hapi Plugin Usage

You can also register this module as an Hapi Plugin and use its provided Falcor handler.

Features

  • Provides restful router with cached routes out of the box.
  • Both the Hapi Request and Reply are available within your routes as this.req and this.reply.
  • Validates your routes with JOI.
  • You can provide your own initialize method to the router.
  • Alternately, you can provide your own Router class and the handler will mixin the logic to cache your routes and the base Falcor router class.
var Hapi = require('hapi');

var app = new Hapi.Server();
app.connection({
    host: "localhost",
    port: 9090
});

app.register(require('falcor-hapi'), function (err) {
   if (err) {
       console.error('Failed to load plugin:', err);
   }

   app.route({
     method: ['GET', 'POST'],
     path: '/model.json',
     handler: {
         falcor: {
             routes: routes,                                         // Your routes
             cacheRoutes: true,                                      // Whether to cache your routes, default to true
             options: {debug: true},                                 // Option to give to Falcor router
             initialize: function() {                                // Optional initialize method
                this.foo = this.req.payload.meaningoflife || 42;
             },
             routerClass: MyRouterClass                              // Optional routerClass to use
         }
     }
   });

   app.start();
});

Development

Please run linting before pushing on repo

npm run lint

Todo

  • Create mocha test for regression and development instead of using example

falcor-hapi's People

Contributors

cilindrox avatar dvemac avatar dzannotti avatar gdibble avatar ggoodman avatar jhusain avatar solenoid avatar theprimeagen avatar

Watchers

 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.