GET /api/v1/feed/messages • HTTP 200 OK

Cursor-Based Pagination API Example — Request & Response Example

Shows how large platforms (Slack, Twitter, Stripe) paginate millions of records reliably without missing items as new entries insert in real-time.

1. HTTP Client Request (GET)

GET /api/v1/feed/messages HTTP/1.1
{
  "Accept": "application/json"
}

2. Server JSON Response (HTTP 200 OK)

{
  "data": [
    {
      "id": "msg_901",
      "text": "Deployment completed successfully.",
      "created_at": 1728211800
    },
    {
      "id": "msg_902",
      "text": "Database replication lag is 0ms.",
      "created_at": 1728211805
    }
  ],
  "pagination": {
    "has_more": true,
    "next_cursor": "cur_9029bf",
    "limit": 2
  }
}

Copy-Paste Code Snippets (cURL, JavaScript Fetch, Python, Node.js)

curl "https://cometflow.space/api/v1/feed/messages?limit=2&cursor=cur_88941a"
fetch('https://cometflow.space/api/v1/feed/messages?limit=2&cursor=cur_88941a')
  .then(res => res.json())
  .then(res => {
    console.log(res.data);
    const next = res.pagination.next_cursor;
  });
import requests

res = requests.get('https://cometflow.space/api/v1/feed/messages', params={'limit': 2, 'cursor': 'cur_88941a'})
print(res.json()['pagination']['next_cursor'])

How This API Call Works Step-by-Step

  1. 1. Client submits cursor pointer.
  2. 2. Database seeks records WHERE id > cursor_id ORDER BY id ASC LIMIT 2.
  3. 3. If additional items exist, has_more is true and next_cursor is returned.
  4. 4. Client stores next_cursor to fetch the next page when the user scrolls.

Backend API Functions: The API function paginateFeed(req, res) decodes the base64 cursor token to an ID/timestamp and executes an efficient indexed index-seek query.

Frequently Asked Questions

Why is cursor pagination better than page/offset pagination?

Offset pagination (OFFSET 100000) causes database performance to degrade drastically because the DB must scan and discard 100,000 rows. Cursor pagination uses index seek (WHERE id > last_seen), executing in sub-millisecond time regardless of table size.