Restify – The future of Node.js REST development

0 179

Get real time updates directly on you device, subscribe now.

1 min read

#Introducing Restify

A Node.js web service framework optimized for building semantically correct RESTful web services ready for production use at scale. Restify optimizes for introspection and perfromance, and is used in some of the largest Node.js deployments on Earth.

#Features of Restify

Production Ready

By production ready we mean to say that the design architecture of Restify framework is well thought out, is stable, is scalable, and very well documented. All these points make Restify to power some of the largest deployments of the industry’s most respected companies.

Debuggable

Running at scale requires the ability to trace problems back to their origin by separating noise from signal. restify is built from the ground up with post-mortem debugging in mind.

Semantically Correct

Staying true to the spec is one of the foremost goals of the project. You will see references to RFCs littered throughout GitHub issues and the codebase.

#Installation


npm install restify

#Usage

Server


var restify = require('restify');

const server = restify.createServer({
  name: 'myapp',
  version: '1.0.0'
});
server.use(restify.plugins.acceptParser(server.acceptable));
server.use(restify.plugins.queryParser());
server.use(restify.plugins.bodyParser());


server.get('/echo/:name', function (req, res, next) {
  res.send(req.params);
  return next();
});

server.listen(8080, function () {
  console.log('%s listening at %s', server.name, server.url);
});

 

Client


var assert = require('assert');
var clients = require('restify-clients');

var client = clients.createJsonClient({

  url: 'http://localhost:8080',
  version: '~1.0'
});

client.get('/echo/mark', function (err, req, res, obj) {
  assert.ifError(err);
  console.log('Server returned: %j', obj);
});