Skip to content

refactor(rest-api-client): align client with rest-api-protocol and add typed ApiClient#1968

Merged
josecelano merged 8 commits into
torrust:developfrom
josecelano:1944-si-6-align-rest-api-client
Jun 30, 2026
Merged

refactor(rest-api-client): align client with rest-api-protocol and add typed ApiClient#1968
josecelano merged 8 commits into
torrust:developfrom
josecelano:1944-si-6-align-rest-api-client

Conversation

@josecelano

Copy link
Copy Markdown
Member

Closes #1944

Summary

Align the REST API client package (torrust-tracker-rest-api-client) with the rest-api-protocol package by introducing a high-level typed ApiClient alongside the existing low-level ApiHttpClient (renamed from Client).

Changes

Refactoring

  • Renamed ClientApiHttpClient across the entire codebase (client, contract tests, E2E tests)
  • Added ApiClient struct with typed methods returning Result<DtoType, ClientError> for all 10 REST API endpoints
  • Added ClientError enum with three variants: TransportError, ApiError (with status + body), DeserializationError

Re-exports

  • AddKeyForm re-exported from rest-api-protocol at the top of the module
  • ApiClient and ApiHttpClient re-exported from v1::mod.rs

Dependencies

  • Added torrust-tracker-rest-api-protocol as a dependency of rest-api-client

Documentation

  • All new public API members have doc comments and # Errors sections

Verification

  • Pre-commit checks pass
  • Pre-push checks pass (122 tests, all passing)

Copilot AI review requested due to automatic review settings June 30, 2026 08:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the torrust-tracker-rest-api-client package to align with rest-api-protocol by introducing a higher-level, typed ApiClient while renaming the existing low-level transport client from Client to ApiHttpClient.

Changes:

  • Renamed ClientApiHttpClient across tests and E2E helpers.
  • Added a new typed ApiClient plus ClientError, and re-exported clients from v1.
  • Added torrust-tracker-rest-api-protocol as a dependency (and updated Cargo.lock).

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/servers/api/contract/stats/mod.rs Updates imports to use ApiHttpClient after rename.
src/console/ci/qbittorrent_e2e/tracker/client.rs Updates E2E wrapper to use ApiHttpClient and adjusts docs.
packages/rest-api-client/src/v1/mod.rs Re-exports ApiClient and ApiHttpClient from v1.
packages/rest-api-client/src/v1/client.rs Introduces ApiClient + ClientError, renames transport client to ApiHttpClient, and re-exports protocol AddKeyForm.
packages/rest-api-client/Cargo.toml Adds torrust-tracker-rest-api-protocol dependency.
packages/axum-rest-api-server/tests/server/v1/contract/context/whitelist.rs Updates contract tests to use ApiHttpClient.
packages/axum-rest-api-server/tests/server/v1/contract/context/torrent.rs Updates contract tests to use ApiHttpClient.
packages/axum-rest-api-server/tests/server/v1/contract/context/stats.rs Updates contract tests to use ApiHttpClient.
packages/axum-rest-api-server/tests/server/v1/contract/context/auth_key.rs Updates contract tests to use ApiHttpClient and protocol AddKeyForm fields.
packages/axum-rest-api-server/tests/server/v1/contract/authentication.rs Updates authentication contract tests to use ApiHttpClient.
docs/issues/open/1944-1938-si-6-align-rest-api-client.md Marks sub-issue tasks as DONE and records clarifying decisions.
Cargo.lock Records the added protocol dependency in the lockfile.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/rest-api-client/src/v1/client.rs
Comment thread packages/rest-api-client/src/v1/client.rs
…oid panics

ApiClient methods now call the  fallible methods on
ApiHttpClient and map failures to ClientError::TransportError,
fulfilling the 'never panics' contract.

Also made ClientError::ApiError variant fields implicitly public
(since the enum itself is pub).
@josecelano josecelano force-pushed the 1944-si-6-align-rest-api-client branch from 7acf385 to 58e7ee0 Compare June 30, 2026 09:55
Clippy requires # Panics documentation on all public methods that
may panic. Added the missing doc sections to all 11 ApiHttpClient
public methods that use .unwrap().
- Added  variant for URL construction failures.
- Added  so  works for transport errors.
- Changed all  fallible methods to return  instead of .
- Made  fallible (returns ) instead of panicking.
-  methods now use  directly with no  calls.
@josecelano

Copy link
Copy Markdown
Member Author

ACK bbd2936

@josecelano josecelano merged commit 5d2d3d2 into torrust:develop Jun 30, 2026
16 checks passed
@josecelano josecelano deleted the 1944-si-6-align-rest-api-client branch June 30, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants