refactor(rest-api-client): align client with rest-api-protocol and add typed ApiClient#1968
Merged
josecelano merged 8 commits intoJun 30, 2026
Conversation
There was a problem hiding this comment.
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
Client→ApiHttpClientacross tests and E2E helpers. - Added a new typed
ApiClientplusClientError, and re-exported clients fromv1. - Added
torrust-tracker-rest-api-protocolas a dependency (and updatedCargo.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.
…d typed ApiClient
…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).
7acf385 to
58e7ee0
Compare
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.
Member
Author
|
ACK bbd2936 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1944
Summary
Align the REST API client package (
torrust-tracker-rest-api-client) with therest-api-protocolpackage by introducing a high-level typedApiClientalongside the existing low-levelApiHttpClient(renamed fromClient).Changes
Refactoring
Client→ApiHttpClientacross the entire codebase (client, contract tests, E2E tests)ApiClientstruct with typed methods returningResult<DtoType, ClientError>for all 10 REST API endpointsClientErrorenum with three variants:TransportError,ApiError(with status + body),DeserializationErrorRe-exports
AddKeyFormre-exported fromrest-api-protocolat the top of the moduleApiClientandApiHttpClientre-exported fromv1::mod.rsDependencies
torrust-tracker-rest-api-protocolas a dependency ofrest-api-clientDocumentation
# ErrorssectionsVerification