New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

revres

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

revres

Incredibly minimal REST api server

latest
npmnpm
Version
0.3.1
Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

REVRES

An incredibly minimal REST api server.

Installation

$ npm install --save revres

Usage

Importing

var revres = require('revres');

Creating a servlet

var servlet = revres([port][, callback]);

Setting a REST endpoint

servlet.get(path, callback);
  • path: string (javascript regex allowed, in string format)
  • callback: function

The callback is called when a request to the given path happens.

Callback params:

  • req: object containing parsed request url data (see node url docs)
  • send: function that takes two parameters (response, content-type)

(Also works with post)

Synchronous

servlet.getSync(path, callback)
  • path: string (javascript regex allowed, in string format)
  • callback: function

Callback params:

  • req: object containing parsed request url data (see node url docs)

When it is time to send a response, just return a string or json object and it will be sent to the client

(Also works with post)

Example

// Create a servlet on port 5000
var servlet = revres(5000);

// Send response 'world' when /hello is requested
servlet.get('/hello', funciton (req, send) {
	send('world');
});

// Count to a number synchronously
servlet.getSync('/count-\\d{1,16}', function (req) {
	var count = parseInt(req.path.split('-')[1]);
	for (var i = 0; i < count; i++) {
		console.log(i);
		if (i > 20000) return 'early';
	}
	return 'done counting';
});

To Do

  • Allow user to pass in server object

FAQs

Package last updated on 13 Jun 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts