app.patch()
Routes HTTP PATCH requests for a path, typically for partial updates.
Syntax
app.patch(path, ...handlers) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
path | string | RegExp | Yes | The route path. |
handlers | ...function | Yes | The handler chain. |
Returns
Application — The app instance, for chaining.
Examples
app.use(express.json());
app.patch('/users/:id', (req, res) => {
const user = patchUser(req.params.id, req.body);
res.json(user);
});
Output
$ curl -X PATCH -d '{"email":"a@b.co"}' -H 'Content-Type: application/json' localhost:3000/users/1
{"id":"1","name":"Ada","email":"a@b.co"}
app.patch('/posts/:id/publish', (req, res) => {
publish(req.params.id);
res.sendStatus(200);
});
Output
(200 OK)
Notes
PATCH applies a partial modification - only send changed fields.
Unlike PUT it is not required to be idempotent. Whitelist allowed
fields server-side to prevent mass-assignment vulnerabilities.