Complete CRUD Endpoint Design
CRUD API
A complete users API can expose:
POST /usersGET /usersGET /users/:idPUT /users/:idPATCH /users/:idDELETE /users/:id
Each endpoint should define request validation, authentication requirements, authorization rules, status codes, response schemas, error cases, logging, metrics, and database behavior.
Do not consider an endpoint complete merely because the happy path works.
Controller Example
async function getUser(req, res, next) {
try {
const user = await userService.getById(req.params.id, req.auth);
if (!user) {
return res.status(404).json({
type: 'user-not-found',
title: 'User not found',
status: 404
});
}
res.status(200).json(user);
} catch (error) {
next(error);
}
}💡 The controller delegates business behavior to the service and maps a known absence to a documented HTTP response.