Skip to content

avayanis/Zzz

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zzz

Zzz is a Lightweight Node.js REST Framework - Currently, Zzz supports the following http request methods: GET, POST, PUT, and DELETE.

Build Status

Installation

$ npm install zzz

Usage

Getting Started

// Load Zzz module and create a server instance
var Zzz = require("zzz");

// Create a new Zzz server
var server = new Zzz.Server();

// Define a GET request
server.get("/my/route", function(request, response) {
	response.end("Hello World, I serve GET requests!")
});

// Define a POST request
server.post("/my/route", function(request, response) {
	response.end("Hello World, I serve POST requests!")
});

// Start listening for requests
server.listen(80);

Routing

Routes are defined by assigning a callback to a http request method and request path:

server.[get|post|put|delete]("/some/path", callback);

server.get("/some/static/path", function(request, response) {
	// do something here
	response.end("I did something.");
});

Zzz will always pass http.serverRequest and http.serverResponse objects to the callback. However, if there are dynamic path segments denoted by a ':', these will be passed via an object of key/value pairs as the third argument to the callback.

server.post("/some/:dynamic/path", function(request, response, uriParams) {
	var body = "";
	
	// do something with post params here
	request.on("data", function(chunk) {
		body += chunk;
	});

	request.on("end", function() {
		var postBody = querystring.parse(body);
		response.write("<p>I was" + uriParams.dynamic + "</p>");
		response.end("<pre>" + postBody + "</pre>");
	});
});

Run Tests

$ make test

Code Coverage Report

$ make coverage

Note: The code coverage report depends on having jscoverage installed.

License: MIT

About

Lightweight Node.js REST service container

Resources

License

Stars

Watchers

Forks

Packages

No packages published