Skip to content

fix(platform): properly join URL paths in HttpClientRequest.appendUrl - #6021

Merged
tim-smart merged 1 commit into
Effect-TS:mainfrom
codewithkenzo:fix/append-url-path-joining
Feb 3, 2026
Merged

tim-smart merged 1 commit into
Effect-TS:mainfrom
codewithkenzo:fix/append-url-path-joining

Conversation

@codewithkenzo

Copy link
Copy Markdown
Contributor

Summary

Fixes HttpClientRequest.appendUrl to properly join URL paths instead of using simple string concatenation.

Closes #5971

Problem

The current implementation could produce invalid URLs:

// Before (broken):
HttpClientRequest.get("https://api.example.com/v1").pipe(
  HttpClientRequest.appendUrl("users")
)
// Result: "https://api.example.com/v1users" (missing slash!)

Solution

Ensure proper path joining by:

  1. Adding a trailing slash to base URL if missing
  2. Removing leading slash from path if present
// After (fixed):
HttpClientRequest.get("https://api.example.com/v1").pipe(
  HttpClientRequest.appendUrl("users")
)
// Result: "https://api.example.com/v1/users"

This matches the behavior of other HTTP client libraries like axios, got, and ky.

Test Cases

Base URL Path Result
https://api.com/v1 users https://api.com/v1/users
https://api.com/v1/ users https://api.com/v1/users
https://api.com/v1 /users https://api.com/v1/users
https://api.com/v1/ /users https://api.com/v1/users

Verification

  • Type check passes (pnpm check)
  • All tests pass (18/18 in HttpClient.test.ts)
  • Changeset added

@changeset-bot

changeset-bot Bot commented Feb 2, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 784721d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 31 packages
Name Type
@effect/platform Patch
@effect/cli Patch
@effect/cluster Patch
@effect/experimental Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/rpc Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-drizzle Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-node Patch
@effect/sql Patch
@effect/workflow Patch
@effect/ai Patch
@effect/ai-amazon-bedrock Patch
@effect/ai-anthropic Patch
@effect/ai-google Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/sql-kysely Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codewithkenzo

Copy link
Copy Markdown
Contributor Author

This implements the fix discussed in #5971 - using smart path joining to ensure a slash exists between base URL and appended path, while preserving the "append" semantics (paths starting with / are still appended, not treated as absolute).

Happy to adjust the approach if you'd prefer full URL spec compliance via new URL() instead.

const request = HttpClientRequest.get("https://api.example.com/v1").pipe(
HttpClientRequest.appendUrl("")
)
strictEqual(request.url, "https://api.example.com/v1/")

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.

Suggested change
strictEqual(request.url, "https://api.example.com/v1/")
strictEqual(request.url, "https://api.example.com/v1")

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.

Nice catch, updated so empty path returns the request unchanged, thank you!

Previously, appendUrl used simple string concatenation which could produce
invalid URLs when the base URL didn't end with a slash and the path didn't
start with one (e.g., '/v1' + 'users' = '/v1users').

Now it ensures proper path joining by:
1. Adding a trailing slash to base URL if missing
2. Removing leading slash from path if present

This matches the behavior of other HTTP client libraries like axios, got, and ky.

Closes #5971
@tim-smart
tim-smart merged commit 0023c19 into Effect-TS:main Feb 3, 2026
11 checks passed
@github-actions github-actions Bot mentioned this pull request Feb 3, 2026
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.

HttpClientRequest.appendUrl should use proper URL concatenation methods

2 participants