|
Download tasks/data/reverse/abdelstark__guts.8876fcf/environment/docs/006-api-design.md from Lego-X/ProgramGen: direct link, hf CLI and curl.
- Browser
- Download file 2.98 kB
-
https://huggingface.co/datasets/Lego-X/ProgramGen/resolve/main/tasks/data/reverse/abdelstark__guts.8876fcf/environment/docs/006-api-design.md
- Command line
-
hf download hf://datasets/Lego-X/ProgramGen/tasks/data/reverse/abdelstark__guts.8876fcf/environment/docs/006-api-design.md
-
curl -L -o 006-api-design.md https://huggingface.co/datasets/Lego-X/ProgramGen/resolve/main/tasks/data/reverse/abdelstark__guts.8876fcf/environment/docs/006-api-design.md
2.98 kB
ADR-006: REST API Design Principles
Status
Accepted
Date
2025-12-20
Context
Guts nodes expose HTTP APIs for:
- Git operations (Smart HTTP protocol)
- Repository management (CRUD)
- Collaboration features (PRs, Issues)
- Governance (Orgs, Teams, Permissions)
- 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