Skip to content

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

Closed

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

  • 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

Activity

  1. self-assigned this
    on Jun 24, 2026
  2. added
    Code Cleanup / Refactoring
    - Developer -
    API
    on Jun 24, 2026
  3. added 2 commits that reference this issue on Jun 24, 2026
  4. added a commit that references this issue on Jun 30, 2026
    5d2d3d2
  5. added 2 commits that reference this issue on Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

- Developer -APICode Cleanup / Refactoringtask

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions