File size: 2,984 Bytes
d086025 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | # 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
- [GitHub REST API](https://docs.github.com/en/rest)
- [RESTful Web APIs (O'Reilly)](https://www.oreilly.com/library/view/restful-web-apis/9781449359713/)
|