hm-nodejs-api-design

Designs REST API routes, Fastify plugins, and Zod validation for Node.js backends.

Updated Apr 26, 2026
One-click install
npx skills add https://github.com/ArkhiMuttaqina/publisher-for-campuss --skill hm-nodejs-api-design-arkhimuttaqina
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: hm-nodejs-api-design
Source: https://github.com/ArkhiMuttaqina/publisher-for-campuss/tree/main/skills/hm-nodejs-api-design
Command: npx skills add https://github.com/ArkhiMuttaqina/publisher-for-campuss --skill hm-nodejs-api-design-arkhimuttaqina

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? It removes guesswork when building Node.js REST APIs by providing concrete conventions for URL design, HTTP status codes, Fastify route plugin structure, and request validation, so teams avoid inconsistent endpoints and misplaced business logic. ## Core Features & Use Cases - REST URL and status code conventions: Plural-noun resource paths, nested routes, and a complete mapping of actions to correct HTTP status codes. - Thin-route Fastify architecture: A three-file module pattern (module/controller/route) that keeps handlers free of business logic and wires dependencies in a composition root. - Zod validation preHandlers: Reusable validateBody, validateQuery, and validateParams hooks that parse and coerce input at the API boundary. - Use Case: When adding a new orders endpoint to a Fastify app, follow the skill to register the module with the correct prefix, apply auth and validation hooks in the right order, and return consistent { data } or { error } responses. ## Quick Start Ask the AI to design a new Fastify REST endpoint for a resource, including the route plugin structure, Zod validation schemas, and correct HTTP status codes.

Frequently Asked Questions about hm-nodejs-api-design

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure Fastify routes in a Node.js project?▼

Split each module into three files: module.ts as the composition root wiring dependencies, controller.ts with thin HTTP handlers, and route.ts defining only paths, methods, and hooks. Register the module in app.ts with a prefix like /api/orders.

How to validate request body in Fastify with Zod?▼

Create a validateBody preHandler hook that calls schema.parse on request.body and passes a ValidationError to done() on failure. Attach it in the route's preHandler array after authentication so downstream code receives typed, coerced data.

What HTTP status code should a REST API return for create and delete?▼

Return 201 Created when a POST successfully creates a resource and 204 No Content for a successful DELETE with no response body. Use 200 OK for GET and updates, 400 for validation failures, 404 for missing resources, and 409 for conflicts.

Does Fastify need try/catch in async route handlers?▼

No. Fastify natively catches errors thrown in async handlers and routes them to the function registered via setErrorHandler. Controllers should throw typed errors like NotFoundError instead of wrapping logic in try/catch blocks.

Why must setErrorHandler be registered before Fastify plugins?▼

Plugins wrapped with fp() inherit the error handler from the parent scope at registration time. Setting handlers after plugin registration causes handler scope isolation bugs in Fastify 5, so error and not-found handlers must be set first in buildApp().

When should route definitions live in module.ts instead of route.ts?▼

For modules with only one or two routes and no complex hooks, route definitions may stay in module.ts. Extract them to a separate route.ts file as soon as routes grow or hooks become non-trivial.