API Reference

restify

Node.js framework optimized for building correct REST APIs, bundling routing, validation, and common plugins.

Official Documentation ↗
CompatibilityThis documentation covers version v12.1.0. Check the official docs for the latest API surface.

Installation

npmnpm install restify
pnpmpnpm add restify

Methods

Overview

restify is a Node.js framework optimized for building correct REST APIs with routing, validation, and a set of common plugins. This reference lists the most frequently used APIs with accurate signatures and runnable snippets.

Core APIs

  • restify.createServer — Creates a server instance with the given name and API version metadata.
  • server.get — Registers a handler for GET requests matching the route.
  • restify.plugins — Provides common middleware such as query, body, and JSONP parsers.

Example

const restify = require('restify');

const server = restify.createServer({ name: 'users-api' });
server.listen(8080, () => console.log(server.url));

Notes

Body parsing must be registered before routes. Errors should flow through next(err) so restify emits a consistent response shape.

Verification

Register a route with body parsing enabled, POST a JSON payload, and confirm the handler sees the parsed body.

Errors

The following points are quoted verbatim from the official documentation. 来源:http://restify.com/docs/home/ · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:52:12.612Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.

FAQ

Why does req.body come back undefined?
Register restify.plugins.bodyParser before the routes so request bodies are parsed before handlers run.
How do I handle errors consistently?
Call next with a restify error, for example next(new restify.errors.BadRequestError("bad")), and add an error listener on the server.
How do I version the API?
Pass version to createServer, then register routes with a version option or use accept-version negotiation.