Skip to content

chore: Update client to use versioned API - #1512

Open
tpoliaw wants to merge 3 commits into
mainfrom
client-api-version
Open

tpoliaw wants to merge 3 commits into
mainfrom
client-api-version

Conversation

@tpoliaw

@tpoliaw tpoliaw commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@tpoliaw
tpoliaw requested a review from a team as a code owner April 24, 2026 13:20
@tpoliaw
tpoliaw requested a review from abbiemery April 24, 2026 13:21
@codecov

codecov Bot commented Apr 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.32%. Comparing base (065ce78) to head (3fefae3).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1512   +/-   ##
=======================================
  Coverage   96.31%   96.32%           
=======================================
  Files          50       50           
  Lines        3831     3833    +2     
=======================================
+ Hits         3690     3692    +2     
  Misses        141      141           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tpoliaw

tpoliaw commented Apr 27, 2026

Copy link
Copy Markdown
Contributor Author

Should be rebased on #1523 to game the coverage check

Comment thread src/blueapi/client/rest.py Outdated

def get_plans(self) -> PlanResponse:
return self._request_and_deserialize("/plans", PlanResponse)
return self._request_and_deserialize("/api/v1/plans", PlanResponse)

@ZohebShaikh ZohebShaikh Apr 28, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

    def _request_and_deserialize(
        self,
        suffix: str,
        target_type: type[T],
        data: Mapping[str, Any] | None = None,
        method="GET",
        get_exception: Callable[[requests.Response], Exception | None] = _exception,
        params: Mapping[str, Any] | None = None,
        prefix:str="/api/v1"
    ) -> T:
        url = self._config.url.unicode_string().removesuffix("/") + prefix + suffix

Something like this looks more maintainable ?

This endpoint will need the /api/v1 prefix as well for this to work

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It would make this a smaller change but does bake in the assumption that v1 will always be the default. If we move to v2 being the main version in future we still need to make this change or accept that we will forever be passing prefix="/api/v2" in every call.

This endpoint will need the /api/v1 prefix as well for this to work

Why couldn't the client pass prefix="" when it was called?

@ZohebShaikh ZohebShaikh Apr 30, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why couldn't the client pass prefix="" when it was called?

We can but I think this should have also move to /api/v1 for consistency

It would make this a smaller change but does bake in the assumption that v1 will always be the default. If we move to v2 being the main version in future we still need to make this change or accept that we will forever be passing prefix="/api/v2" in every call.

for v2 if the above approach the call will look like prefix="api/v2" ,"/endpoint" instead of "/api/v2/endpoint" which is kind off annoying But can't we do something like this

def _request_and_deserialize(endpoint,prefix="api/v1"):
   ...
def _request_and_deserialize_v2(endpoint,prefix="api/v2",):
   _request_and_deserialize(endpoint,prefix)
   ...

and call _request_and_deserialize_v2 ?

Personally I like the approach I have mention of using a prefix but I'm not fussed about it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have gone with the _request_v1 method approach as it doesn't add extra work down the road when v2 becomes the main API.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated this to be a hybrid between the two. _request_and_deserialize doesn't change behaviour and _request_v1 doesn't have to redefine the whole signature.

@tpoliaw
tpoliaw force-pushed the client-api-version branch from 2994cde to d87f06b Compare May 5, 2026 13:04
@abbiemery
abbiemery force-pushed the client-api-version branch from d87f06b to d06db13 Compare May 27, 2026 10:42
@ZohebShaikh
ZohebShaikh self-requested a review June 24, 2026 07:41
@fajinyuan

Copy link
Copy Markdown
Contributor

please resolve conflict here

mock_authn_server.stop() # Cannot use multiple RequestsMock context manager
mock_get_env = mock_authn_server.get(
"http://localhost:8000/environment",
"http://localhost:8000/api/v1/environment",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For the CLI it is okay that we are not testing the old endpoints as we are moving cli to exclusively call v1.
But does it have some benefits if we keep testing the old endpoints. Hopefully nothing bad gets pass through our code-reviews

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have updated test_rest_api to test both old and new routes for the v1 endpoints. I think anything that is testing the client/cli only needs to test the endpoints they are using.

@ZohebShaikh ZohebShaikh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you peter, Look good now with the magic tests for per-v1

This branch has not been deployed

No deployments
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.

3 participants