Cette page est affichée en anglais. Une traduction française est en cours.
ScriptsMay 12, 2026·3 min de lecture

Restify — Purpose-Built Node.js Framework for REST APIs

Restify is a Node.js framework specifically designed for building semantically correct, production-grade RESTful web services with built-in support for DTrace and versioned routes.

Introduction

Restify is a Node.js framework that focuses exclusively on building correct REST APIs. Unlike general-purpose frameworks, it enforces HTTP semantics like proper status codes and content negotiation out of the box. It has been used in production at companies running large-scale API services.

What Restify Does

  • Provides a purpose-built server for creating RESTful APIs with strict HTTP semantics
  • Supports route versioning so multiple API versions can coexist on one server
  • Includes a built-in HTTP client for service-to-service communication
  • Offers DTrace probes for real-time performance analysis on supported platforms
  • Ships with pre-built plugins for parsing, throttling, and CORS

Architecture Overview

Restify uses a handler chain model where each route can have multiple handlers executed in sequence via next(). The server parses incoming requests, matches them against a route table that supports versioned endpoints, and runs the handler chain. Plugins are implemented as middleware functions that hook into the request lifecycle at well-defined points.

Self-Hosting & Configuration

  • Install via npm: npm install restify (requires Node.js 14+)
  • Create a server with restify.createServer({ name, version }) to set API metadata
  • Add pre-route plugins like restify.plugins.bodyParser() for JSON/form parsing
  • Configure throttling with restify.plugins.throttle() to protect endpoints
  • Use server.pre(restify.plugins.pre.sanitizePath()) to normalize request paths

Key Features

  • Built-in API versioning via Accept-Version header or query parameter
  • DTrace integration for live production profiling without restarts
  • Content negotiation with automatic serialization to JSON or custom formats
  • Pluggable audit logging for request/response tracking
  • Semantic error handling with built-in HTTP error constructors

Comparison with Similar Tools

  • Express — general-purpose web framework, more middleware available, less strict on REST semantics
  • Fastify — schema-based validation and faster JSON serialization, broader plugin ecosystem
  • Hapi — configuration-driven with strong input validation, heavier setup
  • Koa — minimalist with async/await middleware, no built-in routing or versioning

FAQ

Q: How does Restify differ from Express? A: Restify is API-only by design. It does not include template rendering, static file serving, or other features aimed at web applications. It enforces correct HTTP behavior by default.

Q: Is Restify still actively maintained? A: Yes. The project continues to receive updates and bug fixes, though the release cadence is slower than larger frameworks.

Q: Can I use Express middleware with Restify? A: Not directly. The middleware signatures differ. Some community adapters exist, but native Restify plugins are recommended.

Q: Does Restify support HTTP/2? A: Restify supports HTTP/2 via Node.js built-in http2 module when configured with TLS certificates.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires