Skip to content

SI-6: Introduce ApiClient — a high-level typed client over protocol DTOs #1944

Description

@josecelano

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 ClientApiHttpClient
  • 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

  • Client renamed to ApiHttpClient across codebase
  • rest-api-protocol added as dependency
  • ClientError enum defined
  • ApiClient struct with typed methods for all endpoints added
  • ApiClient appears before ApiHttpClient in client.rs
  • All existing tests pass unchanged
  • Pre-commit and pre-push checks pass

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions