Skip to content

urljoin

Written as urljoin(argnum flags):options in a transform expression.

Minimum arguments 1
Maximum arguments 1
Default arguments 1
Argument modes SINGLE_PRIMITIVE

Join a base URL with a relative URL path component.

Features:

  • Properly handles joining of URLs according to RFC 3986
  • Resolves relative paths against the base URL
  • Preserves query parameters and fragments when appropriate
  • Automatically adds missing slashes between components

Behavior:

  • If the relative URL is absolute (starts with scheme://), it will be returned as-is
  • If the base URL ends with / and relative URL doesn’t start with /, they are joined directly
  • If base URL doesn’t end with / and relative URL doesn’t start with /, a / is inserted
  • Query parameters and fragments from the relative URL are preserved
Flag Letter
noncaptive_input I
Input args: ["users"]
Transforms: "urljoin:https://example.com/api"
Output: "https://example.com/users"
Input args: ["users"]
Transforms: "urljoin:https://example.com/api/"
Output: "https://example.com/api/users"
Input args: ["http://other.com/path"]
Transforms: "urljoin:https://example.com/api"
Output: "http://other.com/path"
Input args: ["users?id=123"]
Transforms: "urljoin:https://example.com/api/"
Output: "https://example.com/api/users?id=123"
Input args: ["../v2/endpoint"]
Transforms: "urljoin:https://example.com/api/v1/"
Output: "https://example.com/api/v2/endpoint"