Skip to content

coderoshi/webmachine-nodejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Webmachine NodeJS travis

This is a Webmachine toolkit for NodeJS, inspired by the original Erlang Webmachine and Ruby port. Thanks also to Nodemachine for some test scenarios.

Usage

The easiest way to get started is to include webmachine npm project into package.json.

{
  "name": "wmtest",
  "version": "1.0.0",
  "dependencies": {
    "webmachine" : "~>0.0.3"
  }
}

From there, create a webmachine resource. The same functions that can be overridden in other webmachine implementations can be done here, the only difference is that the function names are a JavaScripty camel case style, rather than underscore seperated.

Here is a simple app that adds a root ("/") resource to the service running on port 3000. You can add as many resources as you need. Routes can be an array, and also conform to Sinatra rules (eg. /users/:uid).

var wm = require('webmachine');

var root = {
  route: "/",
  toHtml: function(req, res, next) {
    next("<html><h1>Hello World</h1></html>");
  }
};
wm.add(root);
wm.start(3000, '0.0.0.0');

If you run into issues, you can trace the output. It will present a list of steps taken to arrive at the given response.

wm.trace(true);

The output might not make a lot of sense without this chart, the steps are the decision points.

About

Webmachine HTTP Toolkit for NodeJS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published