Skip to content

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

Open
ynachiket wants to merge 1 commit intoUniversal-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 intoUniversal-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
Copy link
Copy Markdown

google-cla Bot commented Apr 23, 2026

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

1 participant