@fastify/sensible
Sensible defaults and HTTP utilities for Fastify — adds HTTP error helpers, assertions, and common reply methods to every Fastify instance.
@fastify/sensible
FastifySensible defaults and HTTP utilities for Fastify — adds HTTP error helpers, assertions, and common reply methods to every Fastify instance.
Fit
Bundle (gzip)
4.0 kB
11.9 kB raw
Install size includes transitive dependencies. Bundle size is gzipped browser payload.
Freshness
The Problem
Sending correct HTTP error responses in Fastify (with proper status codes and error bodies) requires verbose reply.status(400).send({ message: 'Bad Request' }) calls. There's no built-in shorthand for common HTTP error types.
What It Does
@fastify/sensible adds reply.badRequest(), reply.unauthorized(), reply.notFound(), and 30+ other HTTP error shorthands to every reply object. It also adds request.is() for content type checking and reply.vary() for Vary header management.
Installation
npm install @fastify/sensibleUsage Example
import fastify from 'fastify';
import sensible from '@fastify/sensible';
const app = fastify();
await app.register(sensible);
app.get('/users/:id', async (request, reply) => {
const user = await findUser(request.params.id);
if (!user) return reply.notFound('User not found');
if (!request.user.isAdmin) return reply.forbidden('Admins only');
return user;
});Related packages
Auto-load Fastify plugins from a directory — organize routes and plugins as files and let the framework discover them automatically.
@fastify/cookieFastifyPlugin for Fastify that adds support for reading and setting cookies, including signed cookies.
@fastify/corsFastifyCORS plugin for Fastify — configure cross-origin resource sharing with full support for preflight requests and dynamic origins.
@fastify/helmetFastifySecurity headers plugin for Fastify — sets HTTP headers that protect against common web vulnerabilities like XSS, clickjacking, and MIME sniffing.
@fastify/jwtFastifyJWT authentication plugin for Fastify — sign, verify, and decode tokens with a decorator-based API that integrates with Fastify's request lifecycle.