Skip to content

[API] Implement Pagination on All List Endpoints #71

@fentz26

Description

@fentz26

Problem

List endpoints return all results:

  • Memory issues with large datasets
  • Slow response times
  • No cursor-based navigation

Proposed Solution

Cursor-Based Pagination

type PaginationParams struct {
    Limit  int    // max 100, default 20
    Cursor string // opaque cursor
}

type PaginatedResponse[T any] struct {
    Items      []T    `json:"items"`
    NextCursor string `json:"next_cursor,omitempty"`
    HasMore    bool   `json:"has_more"`
    Total      int    `json:"total,omitempty"`
}

// Cursor encoding
func EncodeCursor(id string, timestamp time.Time) string {
    data := fmt.Sprintf("%s:%d", id, timestamp.UnixNano())
    return base64.StdEncoding.EncodeToString([]byte(data))
}

API Changes

GET /v1/tasks?limit=20&cursor=abc123

Response:
{
    "items": [...],
    "next_cursor": "def456",
    "has_more": true,
    "total": 150
}

Acceptance Criteria

  • All list endpoints support pagination
  • Default limit: 20, max: 100
  • Cursor-based (not offset-based)
  • Link headers for navigation
  • Backward compatibility (no cursor = first page)

References

  • Evaluation Report Section: 1.1 API Design Quality

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions