Skip to content

fix(client): resolve REST endpoint from discovery profile#90

Open
ynachiket wants to merge 1 commit into
Universal-Commerce-Protocol:mainfrom
ynachiket:fix/endpoint-resolution-from-discovery
Open

fix(client): resolve REST endpoint from discovery profile#90
ynachiket wants to merge 1 commit into
Universal-Commerce-Protocol:mainfrom
ynachiket:fix/endpoint-resolution-from-discovery

Conversation

@ynachiket

Copy link
Copy Markdown

The happy path client was ignoring the endpoint field from the /.well-known/ucp discovery response and instead hardcoding all API paths against the initial --server_url.

Per the UCP spec (Endpoint Resolution section):

"The endpoint field provides the base URL for API calls. OpenAPI
paths are appended to this endpoint to form the complete URL."

This works by coincidence when the merchant serves the API at its domain root (e.g. http://localhost:8182), but breaks when the merchant mounts the API under a path prefix (e.g.
https://merchant.com/buy/v1). In that case the client would hit https://merchant.com/checkout-sessions instead of the correct https://merchant.com/buy/v1/checkout-sessions, resulting in 403/404.

This commit:

  • Adds endpoint_resolution.py with the resolve_rest_endpoint() helper
  • Uses the resolved endpoint to recreate the httpx client base_url
  • Updates exported curl URLs to reflect the resolved endpoint
  • Falls back to --server_url if no endpoint is found in discovery
  • Adds 9 unit tests covering path-prefixed, root-level, multi-transport, and missing/empty endpoint scenarios

@ynachiket ynachiket requested review from a team as code owners April 23, 2026 18:42
@ynachiket ynachiket requested review from richmolj and westeezy April 23, 2026 18:42
@google-cla

google-cla Bot commented Apr 23, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@ynachiket ynachiket force-pushed the fix/endpoint-resolution-from-discovery branch 2 times, most recently from 528ebe7 to 8e983bf Compare April 23, 2026 19:03
The happy path client was ignoring the `endpoint` field from the
`/.well-known/ucp` discovery response and instead hardcoding all API
paths against the initial `--server_url`.

Per the UCP spec (Endpoint Resolution section):
> "The endpoint field provides the base URL for API calls. OpenAPI
>  paths are appended to this endpoint to form the complete URL."

This works by coincidence when the merchant serves the API at its
domain root (e.g. `http://localhost:8182`), but breaks when the
merchant mounts the API under a path prefix (e.g.
`https://merchant.com/buy/v1`). In that case the client would hit
`https://merchant.com/checkout-sessions` instead of the correct
`https://merchant.com/buy/v1/checkout-sessions`, resulting in 403/404.

This commit:
- Adds endpoint_resolution.py with the resolve_rest_endpoint() helper
- Uses the resolved endpoint to recreate the httpx client base_url
- Updates exported curl URLs to reflect the resolved endpoint
- Falls back to --server_url if no endpoint is found in discovery
- Adds 9 unit tests covering path-prefixed, root-level, multi-transport,
  and missing/empty endpoint scenarios

Made-with: Cursor
@ynachiket ynachiket force-pushed the fix/endpoint-resolution-from-discovery branch from 8e983bf to 24ca504 Compare April 23, 2026 19:06
@damaz91 damaz91 added status:needs-triage Signal that the PR is ready for human triage status:stale Applied when PR is waiting for author response for 30 days labels Jul 7, 2026
args.export_requests_to,
"PUT",
f"{args.server_url}{url}",
f"{api_base_url}{url}",

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.

If api_base_url happens to have a trailing slash, this can result in double slashes in the logged curl command (e.g., https://example.com/api/v1//checkout-sessions), even though httpx resolves it correctly internally.

A minor improvement would be to use str(response.url) to get the actual resolved URL from the response object, instead of passing the constructed URL string.

@damaz91

damaz91 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Thanks for this fix @ynachiket!

Just added a minor comment, once addressed we can merge this. Please also resolve existing conflicts (I was doing quite some refactoring these days)

@damaz91 damaz91 added status:under-review and removed status:needs-triage Signal that the PR is ready for human triage status:stale Applied when PR is waiting for author response for 30 days labels Jul 13, 2026
@damaz91 damaz91 removed request for a team, richmolj and westeezy July 13, 2026 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants