Conghao97's picture tcftrees's picture
ProgramGen release
d086025
|
Raw History Blame Contribute Delete
2.98 kB

ADR-006: REST API Design Principles

Status

Accepted

Date

2025-12-20

Context

Guts nodes expose HTTP APIs for:

  1. Git operations (Smart HTTP protocol)
  2. Repository management (CRUD)
  3. Collaboration features (PRs, Issues)
  4. Governance (Orgs, Teams, Permissions)
  5. Webhooks and integrations

The API design should be:

  • Intuitive for developers familiar with GitHub/GitLab
  • RESTful and predictable
  • Consistent across all endpoints

Decision

We adopt a REST API design following these principles:

URL Structure

HTTP Methods

Method Usage Example
GET Read resources GET /api/repos/alice/project/pulls
POST Create resources POST /api/repos/alice/project/pulls
PATCH Partial update PATCH /api/repos/alice/project/pulls/1
PUT Full replace / Upsert PUT /api/repos/alice/project/collaborators/bob
DELETE Remove resources DELETE /api/repos/alice/project/hooks/123

Request/Response Format

All requests and responses use JSON:

HTTP Status Codes

Code Meaning Usage
200 OK Successful GET, PATCH
201 Created Successful POST
204 No Content Successful DELETE
400 Bad Request Invalid input
401 Unauthorized Missing authentication
403 Forbidden Insufficient permissions
404 Not Found Resource doesn't exist
409 Conflict State conflict (e.g., already merged)
422 Unprocessable Valid JSON, invalid semantics

Pagination

List endpoints use offset-based pagination:

Filtering

Query parameters for filtering:

Using Axum for HTTP handling:

Consequences

Positive

  • Familiar: Developers can guess endpoints
  • Toolable: Works with standard HTTP clients
  • Debuggable: Human-readable JSON
  • Documented: OpenAPI spec can be generated

Negative

  • Chatty: Multiple requests for related data
  • Overfetching: Returns full objects even for partial needs
  • No subscriptions: Polling required for updates

Neutral

  • Authentication header required for private resources
  • Rate limiting can be applied uniformly

Authentication

Currently using header-based identity:

Future enhancement: Signature-based authentication:

Alternatives Considered

GraphQL

Single endpoint with query language.

Deferred because:

  • Higher complexity
  • Git endpoints still need REST
  • May add later for web clients

gRPC

Binary protocol with generated clients.

Deferred because:

  • Less accessible for debugging
  • Browser compatibility requires proxy
  • May add for high-performance use cases

JSON-RPC

Remote procedure call over HTTP.

Rejected because:

  • Less discoverable
  • Non-standard patterns
  • REST is more widely understood

References