Pagination
The Instagram Hashtag Feed API uses simple limit-based pagination for controlling the number of results returned.
How It Works
The API supports a limit parameter that controls the maximum number of items returned in a single request.
Parameters
- limit (integer, optional): Maximum number of items to return
- Minimum: 1
- Maximum: 100
- Default: 25
Examples
Get the first 10 items
curl http://localhost:3000/api/feed?hashtags=family,kids&limit=10
Get maximum items (100)
curl http://localhost:3000/api/feed?hashtags=family,kids&limit=100
Use default limit (25 items)
curl http://localhost:3000/api/feed?hashtags=family,kids
Response Format
The response always includes a count field indicating the number of items returned:
{
"count": 10,
"items": [
// ... feed items
]
}
Sorting
Results are always sorted newest-first by the timestamp field. This ensures the most recent posts appear at the top of the feed.
Limitations
Current Implementation
The current API uses simple limit-based pagination, which has some limitations:
- No cursor or offset support
- Cannot fetch items beyond the first result set
- Limited to 100 items per request
For Production Use
For production applications, consider implementing:
- Cursor-based Pagination: Use a cursor (timestamp or ID) to fetch the next set of results
- Offset Pagination: Support
offsetparameter for skipping results - Link Headers: Include
nextandprevlinks in response headers - Page Numbers: Support page-based navigation
Example: Fetching All Available Items
Since the API currently doesn't support cursor-based pagination, you can only retrieve up to 100 items per request:
async function fetchMaxItems(hashtags) {
const response = await fetch(
`http://localhost:3000/api/feed?hashtags=${hashtags}&limit=100&mode=mock`
);
const data = await response.json();
console.log(`Fetched ${data.count} items`);
return data.items;
}
Caching Considerations
The API implements caching with a default TTL of 120 seconds. When paginating through results:
- Identical requests within the cache window return cached data
- The cache key includes the hashtags and limit parameters
- Changing these parameters will result in a new cache entry
Best Practices
- Request only what you need: Use the
limitparameter to fetch only the number of items you'll display - Consider caching on the client: Cache results to reduce unnecessary API calls
- Handle empty results: Always check the
countfield to see if results were returned - Monitor performance: Large
limitvalues may impact response time