Code Monkey home page Code Monkey logo

dagger's Introduction

Dagger

Minimal API web server framework for Node.js

** Alpha, use at your own risk **

Dagger is the backend of a minimal web API server for rapidly prototyping super-lightweight node.js services.

Dagger offers:

  • The ability to rapidly develop web APIs and flexibly integrate services of all types in minimal time.
  • An incredibly tight end product. None of the dependency bloat or slow startup of Express.js
  • Predictability, readability and maintainability of its code.

Express and other web frameworks encourage anti-patterns like the Connect-style responder chain, which distributes portions of the request-parsing and response-generating code into vastly different (sometimes opaque) places in your source and decreases predictability (and maintainability.) Dagger is totally focused on making the HTTP request-response paradigm straightforward, even in the most complex cases. Nobody modifies the request or messes with the response but you.

Installation

npm install dagger

Usage

var server = new Dagger.Server(
{ "/":     homeServer,
  "static":  staticServer,
  "api":     new Dagger.Router(
  {
    "/users": Dagger.APIEndpoint(users.getAll, users),
    "/users/:username": Dagger.APIEndpoint(users.getByName, users),
  }),
}, 8000);

function getAll(request, response, args, callback)
{
  storageLayer.users.all(function(err, users)
  {
    if(err)
      return(callback(undefined, 500));  //return HTTP 500 and no data
    
    if(users.length == 0)
      return(callback([], 404));  //return HTTP 404 and an empty list

    callback(users);  //returning HTTP 200 is the default
  });
}

function getByName(request, response, args, callback)
{
  storageLayer.users.some({name: args.url.username}, function(err, user)
  {
    if(err)
      return(callback(undefined, 500));  //return HTTP 500 and no data
    
    callback(user);
  }
}

dagger's People

Contributors

kuym avatar

Stargazers

 avatar

Watchers

James Cloos avatar  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.