res.links()

Sets the Link response header from a relation-to-URL object.

Since Express 4 Spec ↗

Syntax

res.links(links)

Parameters

NameTypeRequiredDescription
links object Yes An object mapping link relations (`next`, `prev`, `last`) to URLs.

Returns

Response — The response object, for chaining.

Examples

app.get('/users', (req, res) => {
  res.links({
    next: '/users?page=3',
    prev: '/users?page=1',
  });
  res.json(getPage(req.query.page));
});
Output
Link: </users?page=3>; rel="next", </users?page=1>; rel="prev"
app.get('/items', (req, res) => {
  res.links({ last: '/items?page=10' }).end();
});
Output
Link: </items?page=10>; rel="last"

Notes

Produces a properly formatted RFC 8288 `Link` header, commonly used for API pagination (GitHub-style). Multiple calls append rather than replace, so build the full set in one call when possible.

See also