urljoin
Written as urljoin(argnum flags):options in a transform expression.
| Minimum arguments | 1 |
| Maximum arguments | 1 |
| Default arguments | 1 |
| Argument modes | SINGLE_PRIMITIVE |
Documentation
Section titled “Documentation”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 |
Examples
Section titled “Examples”Basic URL joining
Section titled “Basic URL joining”Input args: ["users"]Transforms: "urljoin:https://example.com/api"Output: "https://example.com/users"With trailing slash
Section titled “With trailing slash”Input args: ["users"]Transforms: "urljoin:https://example.com/api/"Output: "https://example.com/api/users"Absolute relative URL
Section titled “Absolute relative URL”Input args: ["http://other.com/path"]Transforms: "urljoin:https://example.com/api"Output: "http://other.com/path"With query parameters
Section titled “With query parameters”Input args: ["users?id=123"]Transforms: "urljoin:https://example.com/api/"Output: "https://example.com/api/users?id=123"Complex path joining
Section titled “Complex path joining”Input args: ["../v2/endpoint"]Transforms: "urljoin:https://example.com/api/v1/"Output: "https://example.com/api/v2/endpoint"