Link Header Pagination — REST API Pagination Header Implementation Errors
Informational2xx success
Overview
Fix Link header pagination errors in REST APIs including malformed Link headers, missing rel values, and client parsing failures for paginated responses.
Key Details
- Link headers provide pagination URLs for REST APIs following RFC 8288 (Web Linking)
- Standard rel values are: first, prev, next, last — indicating pagination directions
- GitHub API popularized this pattern: Link: <url>; rel="next", <url>; rel="last"
- Link headers keep pagination metadata in headers rather than the response body
- Parsing Link headers requires handling URL encoding, quoted strings, and multiple values
Common Causes
- Link header format not following RFC 8288 — missing angle brackets around URLs or quotes around rel values
- URL parameters in Link header not properly encoded (& characters in URLs)
- Client not parsing Link headers and instead hard-coding pagination logic
- Server not including Link headers for the last page, confusing client pagination logic
Steps
- 1Format Link headers correctly: Link: <https://api.example.com/items?page=2>; rel="next", <https://api.example.com/items?page=5>; rel="last"
- 2URL-encode any special characters in the Link header URLs
- 3Include all four rel values (first, prev, next, last) where applicable — omit prev on page 1 and next on the last page
- 4Use a Link header parsing library in your client (parse-link-header for Node.js, or regex for simple cases)
- 5Also include pagination metadata in the response body (total_count, page, per_page) for convenience
Tags
link-headerpaginationrest-apirfc-8288web-linking
More in 2xx Success
http-200-okHTTP 200 OK — What It Means & How to Fix It
Informationalhttp-201-createdHTTP 201 Created — What It Means & How to Fix It
Informationalhttp-202-acceptedHTTP 202 Accepted — What It Means & How to Fix It
Informationalhttp-203-non-authoritative-informationHTTP 203 Non-Authoritative Information — What It Means & How to Fix It
Informationalhttp-204-no-contentHTTP 204 No Content — What It Means & How to Fix It
Informationalhttp-205-reset-contentHTTP 205 Reset Content — What It Means & How to Fix It
InformationalFrequently Asked Questions
Link headers separate pagination metadata from resource data, following HATEOAS principles. The client does not need to know the URL structure — it just follows the provided links.