Link Headers — RFC 5988 Pagination Navigation
DodaTech
Updated 2026-06-28
1 min read
In this tutorial, you will learn about Link Headers. We cover key concepts, practical examples, and best practices to help you master this topic.
Link headers provide pagination navigation URLs following RFC 5988, using rel values for prev, next, first, and last to guide client pagination without Parsing response bodies.
Header Format
Link: <https://api.example.com/users?page=1>; rel="first",
<https://api.example.com/users?page=3>; rel="next",
<https://api.example.com/users?page=10>; rel="last"
Implementation
app.get("/api/users", async (req, res) => {
const page = parseInt(req.query.page) || 1;
const limit = Math.min(parseInt(req.query.limit) || 20, 100);
const total = await getTotalCount();
const pages = Math.ceil(total / limit);
const links = [];
const baseUrl = `${req.protocol}://${req.get("host")}${req.baseUrl}${req.path}`;
links.push(`<${baseUrl}?page=1&limit=${limit}>; rel="first"`);
if (page > 1) {
links.push(`<${baseUrl}?page=${page - 1}&limit=${limit}>; rel="prev"`);
}
if (page < pages) {
links.push(`<${baseUrl}?page=${page + 1}&limit=${limit}>; rel="next"`);
}
links.push(`<${baseUrl}?page=${pages}&limit=${limit}>; rel="last"`);
res.set("Link", links.join(", "));
res.json({ data: results });
});
Common Mistakes
- Absolute URL confusion — Using relative URLs instead of absolute.
- Missing first/last — Only providing prev and next.
- No Link header at all — Relying only on body metadata.
Practice Questions
- What are the standard Link rel values?
- How do you construct navigation URLs?
- Why use Link headers in addition to body metadata?
Challenge
Implement Link headers for a paginated API. Include first, prev, next, and last links. Handle edge cases like first page and last page.
What's Next
In the final lesson, you will complete a pagination project.
← Previous
Pagination Metadata — Response Format Conventions
Next →
Pagination Project — Building a Complete Paginated API
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro