Skip to content

Release 0.4.0: preserve base-URL path prefixes - #6

Merged
azeemshaik025 merged 1 commit into
mainfrom
feat/v0.4.0
Aug 24, 2026
Merged

Release 0.4.0: preserve base-URL path prefixes#6
azeemshaik025 merged 1 commit into
mainfrom
feat/v0.4.0

Conversation

@azeemshaik025

Copy link
Copy Markdown
Owner

Summary

Fixes a long-standing footgun: a base URL with a path prefix (e.g. https://api.example.com/v1) had its prefix silently dropped, so beckon requested /users instead of /v1/users — mysterious 404s against APIs like Stripe (/v1) on the very first call.

Root cause

Endpoint paths carry a leading / (absolute references), and Url::join follows RFC 3986 — an absolute path replaces the base path. (Not a reqwest/url bug; base-URL-as-prefix is a known request reqwest declined, left to userland. beckon is that layer.)

Fix

Two small changes, no new dependency — reuses Url::set_path, Url::join, str::trim_start_matches, and the existing segment encoder:

  • Normalize the base to a trailing / once, at construction (with_client; new delegates to it).
  • Join endpoint paths relative to the base (strip the leading /).
Base Path Before After
…/v1 /users …/users …/v1/users
…/v1/ /users …/users …/v1/users
https://api.x.com /users …/users …/users ✅ (unchanged)

Bases without a path prefix — which every example/test uses — are byte-for-byte unchanged, so in practice this breaks no one; it's shipped as a minor with a changelog note because it is a behavior change.

Tests

Matrix added: base {no prefix, /v1, /v1/} × path {no params, params, param containing /} + a no-prefix regression test. Verified on the CI toolchain (cargo +stable): fmt, clippy -D warnings, 33 tests + doctests — all green.

Fixed:
- A base URL with a path prefix (e.g. https://api.example.com/v1) had its prefix
  dropped when an endpoint path was joined, because an absolute path replaces the
  base path per RFC 3986. The base is now normalized to a trailing `/` and endpoint
  paths are joined relative to it, so `/v1` + `/users` → `/v1/users`. Bases without a
  path prefix are unaffected.

Uses existing primitives only (Url::set_path, Url::join, str::trim_start_matches,
and the existing segment encoder) — no new dependency.

Tests: base {no prefix, /v1, /v1/} x path {params, no params, param with `/`} plus a
no-prefix regression test.
@azeemshaik025
azeemshaik025 merged commit 1664b0a into main Aug 24, 2026
1 check passed
@azeemshaik025
azeemshaik025 deleted the feat/v0.4.0 branch August 24, 2026 04:23
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