Subissue of EPIC #1938 — REST API Contract-First Migration
Problem
The REST API client package (torrust-tracker-rest-api-client) currently exposes only a low-level Client where all methods return raw reqwest::Response. Callers parse the body manually. Some methods panic via .unwrap(). External consumers (Torrust Index, E2E tests) build their own ad-hoc wrappers.
Decision
Introduce a two-tier client architecture in packages/rest-api-client/src/v1/client.rs:
ApiHttpClient (renamed from Client) — low-level HTTP transport. Handles connection info, URL building, auth headers. Returns raw Response.
ApiClient (new) — high-level typed client wrapping ApiHttpClient. Returns Result<DtoType, ClientError>. Never panics.
Scope
- Rename existing
Client → ApiHttpClient
- Add
rest-api-protocol as dependency
- Define
ClientError enum (transport, deserialization, API error responses)
- Add
ApiClient struct before ApiHttpClient in client.rs
- Implement typed methods on
ApiClient for all endpoints
Checklist
Subissue of EPIC #1938 — REST API Contract-First Migration
Problem
The REST API client package (
torrust-tracker-rest-api-client) currently exposes only a low-levelClientwhere all methods return rawreqwest::Response. Callers parse the body manually. Some methods panic via.unwrap(). External consumers (Torrust Index, E2E tests) build their own ad-hoc wrappers.Decision
Introduce a two-tier client architecture in
packages/rest-api-client/src/v1/client.rs:ApiHttpClient(renamed fromClient) — low-level HTTP transport. Handles connection info, URL building, auth headers. Returns rawResponse.ApiClient(new) — high-level typed client wrappingApiHttpClient. ReturnsResult<DtoType, ClientError>. Never panics.Scope
Client→ApiHttpClientrest-api-protocolas dependencyClientErrorenum (transport, deserialization, API error responses)ApiClientstruct beforeApiHttpClientinclient.rsApiClientfor all endpointsChecklist
Clientrenamed toApiHttpClientacross codebaserest-api-protocoladded as dependencyClientErrorenum definedApiClientstruct with typed methods for all endpoints addedApiClientappears beforeApiHttpClientinclient.rs