Guide · Open source
How to use node-restify: install, build a REST API and tips
Updated · written with AI from the project's own documentation and checked against our catalogue data
Restify is a JavaScript framework for building REST APIs on Node.js. It uses middleware in the style of the connect library, so you add reusable pieces such as body parsers and query parsers to a server, then define routes for GET, POST and other HTTP methods. This guide is for developers who already know JavaScript and npm and want to build web services that other programs call over HTTP. By the end you will have installed restify, run a small server and called it with the companion client library.
Quick start
- 1Check your Node.js version. Make sure Node.js is v22.x, v24.x or v26.x, the versions the project lists as supported.
- 2Install restify. Run npm install restify in your project folder.
- 3Create the server. Call restify.createServer with a name and version.
- 4Add middleware. Use server.use to add the accept, query and body parsers.
- 5Define a route. Use server.get with a path and handler, and call next() at the end.
- 6Start listening. Call server.listen with a port, then test the route in your browser or with a client.
Install restify with npm
Restify is installed as a package through npm. The project supports Node.js v22.x, v24.x and v26.x, so check your Node.js version before you start.
- Confirm you are running a supported Node.js version (v22.x, v24.x or v26.x).
- Run the install command inside your project folder.
$ npm install restifyCreate a server and add middleware
Call restify.createServer with a name and version, then attach middleware with server.use. The README example adds an accept parser, a query parser and a body parser. Middleware runs for incoming requests before your route handlers.
The name and version options identify your app. The example passes name 'myapp' and version '1.0.0'.
- restify.plugins.acceptParser(server.acceptable) checks the Accept header.
- restify.plugins.queryParser() parses query string parameters.
- restify.plugins.bodyParser() parses request bodies.
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());Define routes for GET and other HTTP methods
Routes are defined by HTTP method and path. The README example defines a GET route with a named path parameter, :name, and sends the parsed parameters back with res.send. Each handler ends by calling next(), which passes control on.
Restify also supports other HTTP methods such as POST, which the framework description mentions. The README example only shows GET.
- Use server.get(path, handler) for GET requests.
- Read path parameters from req.params.
- Call res.send to return a response and return next() to finish the handler.
server.get('/echo/:name', function (req, res, next) {
res.send(req.params);
return next();
});Start the server
Call server.listen with a port and a callback. The example listens on port 8080 and logs the server name and URL once it is running.
server.listen(8080, function () {
console.log('%s listening at %s', server.name, server.url);
});Call your API with restify-clients
The README describes restify-clients as a companion library for calling your own API. The example creates a JSON client pointed at the local server, with a version range of ~1.0, and sends a GET request to /echo/mark.
The client callback receives err, req, res and the parsed object. The example checks err with assert.ifError and logs the returned object.
- Install restify-clients separately if you need it; the README example requires it as 'restify-clients'.
- The client version option is set to '~1.0' in the example.
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);
});What people use it for
- Building a JSON web service that other programs call over HTTP.
- Adding reusable middleware such as body and query parsers to an API server.
- Writing a small client with restify-clients to call your own API during development.
- Exposing GET routes with path parameters, such as /echo/:name in the example.
Frequently asked questions
How do I install restify?
Run npm install restify in your project folder. The project lists Node.js v22.x, v24.x and v26.x as supported versions, so use one of those.
Is restify free to use?
Yes. Restify is released under the MIT License, which permits use, copy, modify, merge, publish, distribute, sublicense and sell of the software, subject to including the copyright notice. The license states the software is provided as is, without warranty.
What Node.js versions does restify support?
The README says restify currently works on Node.js v22.x, v24.x and v26.x. The README does not list other runtimes.
Is restify good for beginners?
The examples assume working knowledge of JavaScript and npm. Beginners with no Node.js experience should learn the basics first.
How is restify different from Express?
The README describes restify as a framework built for REST APIs that uses connect-style middleware. Express, Fastify, Koa and Hapi are listed as comparable projects; this page does not benchmark them against each other.
Where can I report a bug or ask a question?
The README points to the issue tracker at github.com/restify/node-restify/issues for bugs, and to a Google group mailing list for discussion.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
Restify suits Node.js developers who are building JSON or REST web services and want connect-style middleware on a server made for APIs. It is a poor fit if you need a full-stack framework with views, templates and front-end tooling, or if you are new to Node.js and npm. Pick Express, Fastify, Koa or Hapi if their ecosystems or features fit your project better.
Install options & downloads