orator
Restful web API server. Using restify 6.
Last updated 2 years ago by jasonhillier .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install orator 
SYNC missed versions from official npm registry.

Orator

Orator API Server, meant to interact well with Fable, Meadow and FoxHound.

Coverage Status Build Status Dependency Status devDependency Status

This is not an attempt to reinvent the wheel. Nor do we want to make a car with five of them.

Orator is a wrapper for restify, which is an amazing API server. With Orator, you can spin up a web server in a single simple line. And config settings are managed via a consistent json format, so as you begin to have 10 or 15 or 5,000 microservices, you don't have a bunch of boilerplate API server code laying around.

Creating a Simple Server

Okay, so you want to make a simple api server. You would need to create a node.js project, then install the Orator dependency with npm:

npm install orator --save

Then within your javascript code, you could write the following:

// Load the orator module with a few settings
var libOrator = require('orator').new(
	{
		Product: 'MyMicroserviceHash',
		ProductVersion: '9.8.7',

		"APIServerPort": 8000
	});

// Add an API endpoint
libOrator.webServer.post
(
	'/echo/:name',
	function(pRequest, pResponse, fNext)
	{
		// Send back whatever was sent as "name" in the URI
		pResponse.send(pRequest.params);
		return fNext();
	}
);

// Start the web service
libOrator.startWebServer();

After writing this code, you could run your service and a browser going to http://localhost:8000/echo/Gargamel would return a JSON object with Gargamel as the name.

Of course, this is not much different from the Restify code. Where it gets interesting is dealing with things like logging and configuration management. For instance, if you do

// Load the orator module with a few settings
var libOrator = require('orator').new(
	{
		Product: 'MyMicroserviceHash',
		ProductVersion: '9.8.7',

		"APIServerPort": 8000,

		ConfigFile:__dirname+'/MyMicroservice-Config.json'
	});

// Add an API endpoint
libOrator.webServer.post
(
	'/echo/:name',
	function(pRequest, pResponse, fNext)
	{
		// Send back whatever was sent as "name" in the URI
		pResponse.send(pRequest.params);
		return fNext();
	}
);

// Start the web service
libOrator.startWebServer();

Then you could create a file in the same folder as this script called MyMicroservice-Config.json and as long as it is valid json, settings can be loaded from there. Something like this:

{
	"APIServerPort": 8080,

	"UUID":
		{
			"DataCenter": 0,
			"Worker": 0
		},

	"LogStreams":
		[
			{
				"level": "info",
				"path": "./MyMicroService-Server.log"
			},
			{
				"level": "trace",
				"streamtype": "process.stdout"
			}
		]
}

And suddenly the bunyan logging will write to a file and stdout, and you can configure 20 Docker instances to each have a different Worker ID.

Current Tags

  • 2.0.4                                ...           latest (2 years ago)

44 Versions

  • 2.0.4                                ...           2 years ago
  • 2.0.3                                ...           2 years ago
  • 2.0.2                                ...           2 years ago
  • 2.0.1                                ...           2 years ago
  • 1.1.27                                ...           2 years ago
  • 1.1.26                                ...           2 years ago
  • 1.1.25                                ...           2 years ago
  • 1.1.24                                ...           2 years ago
  • 1.1.23                                ...           2 years ago
  • 1.0.22                                ...           3 years ago
  • 1.0.21                                ...           3 years ago
  • 1.0.20                                ...           3 years ago
  • 1.0.19                                ...           3 years ago
  • 1.0.18                                ...           4 years ago
  • 1.0.17                                ...           4 years ago
  • 1.0.16                                ...           4 years ago
  • 1.0.15                                ...           4 years ago
  • 1.0.14                                ...           4 years ago
  • 1.0.13                                ...           5 years ago
  • 1.0.12                                ...           5 years ago
  • 1.0.10                                ...           5 years ago
  • 1.0.9                                ...           5 years ago
  • 1.0.8                                ...           5 years ago
  • 1.0.7                                ...           5 years ago
  • 1.0.6                                ...           5 years ago
  • 1.0.5                                ...           5 years ago
  • 1.0.4                                ...           5 years ago
  • 1.0.3                                ...           5 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 0.1.13                                ...           5 years ago
  • 0.1.12                                ...           5 years ago
  • 0.1.11                                ...           5 years ago
  • 0.1.10                                ...           5 years ago
  • 0.1.9                                ...           5 years ago
  • 0.1.8                                ...           5 years ago
  • 0.1.7                                ...           5 years ago
  • 0.1.6                                ...           5 years ago
  • 0.1.5                                ...           5 years ago
  • 0.1.4                                ...           5 years ago
  • 0.1.3                                ...           6 years ago
  • 0.1.2                                ...           6 years ago
  • 0.1.1                                ...           6 years ago
  • 0.0.0                                ...           6 years ago
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 0
Dependencies (10)
Dev Dependencies (7)

Copyright 2014 - 2017 © taobao.org |