Skip to content

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

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

fix(platform): properly join URL paths in HttpClientRequest.appendUrl#6021
tim-smart merged 1 commit intoEffect-TS:mainfrom
codewithkenzo:fix/append-url-path-joining

Conversation

@codewithkenzo
Copy link
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

@github-project-automation github-project-automation bot moved this to Discussion Ongoing in PR Backlog Feb 2, 2026
@changeset-bot
Copy link

changeset-bot bot commented Feb 2, 2026

🦋 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
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
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
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 Effect-TS#5971
@codewithkenzo codewithkenzo force-pushed the fix/append-url-path-joining branch from 07dd995 to 784721d Compare February 2, 2026 22:47
@tim-smart tim-smart merged commit 0023c19 into Effect-TS:main Feb 3, 2026
11 checks passed
@github-project-automation github-project-automation bot moved this from Discussion Ongoing to Done in PR Backlog Feb 3, 2026
@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

Status: Done

Development

Successfully merging this pull request may close these issues.

HttpClientRequest.appendUrl should use proper URL concatenation methods

2 participants