API reference

Parse a URL

Split a URL into its parts with the WHATWG URL parser browsers use.

GETPOST/api/url/parseMCP tool url_parse

Parses a URL exactly as browsers and Cloudflare Workers do (WHATWG URL Standard) and returns every component: scheme, username, host in ASCII and Unicode forms, port and default port, origin, path segments decoded, query parameters as an ordered list (duplicates kept), and fragment. It classifies the host (domain, IPv4, IPv6, localhost, private or other special-purpose range) without resolving DNS. A password, if present, is never returned: hasPassword is true and href shows *** instead. With base, a relative reference is resolved first.

Browser version (runs locally): URL Parser.

Try it

Credentials
Remember these credentials

Not saved: you will paste them again next time.

No credentials yet? Get a client ID and secret. They are sent only to this site, in an Authorization: Basic header.

POST /api/url/parse with a JSON body

Parameters

ParameterTypeDefaultDescription
inputrequiredstring (≤ 16384 chars)—The URL, absolute (https://…), or relative (../a?b=1) when base is given.
basestring (≤ 16384 chars)—Absolute base URL for resolving a relative input (RFC 3986 §5 as refined by WHATWG). Ignored when input is absolute.

Also accepted on every endpoint: format (json | text). Parameters may come from the query string, a JSON object body, an urlencoded or multipart form, or (for input) a text/plain body.

Global parameters
ParameterTypeDefaultDescription
formatjson | textjsonjson returns the documented object. text returns only the primary value as text/plain (see "Text output").

Response 200 application/json

FieldTypeDescription
hrefstringThe normalized URL (WHATWG serialization). If the input had a password, it is replaced by ***.
hrefRedactedbooleanTrue when href had its password replaced.
resolvedAgainstBasebooleanTrue when the input was relative and was resolved against base.
protocolstringScheme with the colon, e.g. https:.
schemestringScheme without the colon, lowercase.
specialbooleanA WHATWG special scheme (http, https, ws, wss, ftp, file).
usernameobject
username.rawstringAs serialized in the normalized URL (percent-encoded).
username.decodedstring | nullPercent-decoded as UTF-8; null if an escape is not valid UTF-8.
hasPasswordbooleanTrue when the URL contains a password. The password is never returned.
hoststringHost plus :port when a non-default port is present (ASCII).
hostnamestringHost without port, ASCII (Punycode) form. IPv6 includes brackets.
hostnameUnicodestringHost with xn-- labels decoded to Unicode (equal to hostname otherwise).
hostType"domain" | "ipv4" | "ipv6" | "opaque" | "empty" | "none"domain, ipv4, ipv6, opaque (host of a non-special scheme), empty (e.g. file:///), or none (no authority, e.g. mailto:).
idnbooleanTrue when any host label is an xn-- (internationalized) label.
ipobject | null
ip.versioninteger4 or 6.
ip.addressstringAddress as normalized by the URL parser (no brackets).
ip.expandedstringIPv6: all eight 4-digit groups. IPv4: dotted decimal.
ip.range"public" | "private" | "loopback" | "link-local" | "unspecified" | "shared" | "multicast" | "broadcast" | "documentation" | "benchmarking" | "reserved" | "unique-local" | "ipv4-mapped" | "nat64" | "site-local"Special-purpose range (IANA registries), or public.
ip.mappedIpv4string | nullEmbedded IPv4 address for ::ffff:0:0/96 and 64:ff9b::/96.
isLocalhostbooleanlocalhost, *.localhost (RFC 6761), or a loopback IP.
isPrivatebooleanIP in RFC 1918, RFC 6598 shared (100.64/10), fc00::/7 or fec0::/10 (including IPv4-mapped forms).
isPublicboolean | nullTrue for a global unicast IP; false for any special-purpose IP or localhost; null for a domain name (it is not resolved).
portinteger | nullExplicit non-default port, or null.
defaultPortinteger | nullDefault port of the scheme (http 80, https 443, ws 80, wss 443, ftp 21).
effectivePortinteger | nullport ?? defaultPort: the port a client would connect to.
originstring | nullscheme://host[:port]; null for opaque origins (file:, data:, mailto:, …).
pathnamestringPath as serialized (percent-encoded).
opaquePathbooleanTrue for URLs like mailto:a@b whose path is not a /-separated list.
pathSegmentsarray of objectPath segments split on /; empty for opaque paths.
pathSegments[].rawstringAs serialized in the normalized URL (percent-encoded).
pathSegments[].decodedstring | nullPercent-decoded as UTF-8; null if an escape is not valid UTF-8.
searchstringQuery string including ?, or empty.
queryarray of objectQuery parameters in order. Duplicate names are kept as separate entries.
query[].namestringDecoded name (application/x-www-form-urlencoded: + is a space).
query[].valuestringDecoded value; empty string when there is no =.
query[].rawNamestringName as it appears in the URL.
query[].rawValuestring | nullValue as it appears in the URL; null when there is no =.
hashstringFragment including #, or empty.
fragmentobject | null
fragment.rawstringAs serialized in the normalized URL (percent-encoded).
fragment.decodedstring | nullPercent-decoded as UTF-8; null if an escape is not valid UTF-8.
warningsarray of stringNormalizations applied and risks found.

Text output (format=text, text/plain): The normalized href (password redacted).

Errors

Errors are JSON: {"error": "<message>", "code": "<code>", "param": "<name>"?}.

StatusCodeWhen
422unprocessable_inputinput is not a valid URL (the message suggests the likely cause: no scheme, bad host character, bad port), or base is not a valid absolute URL.
400missing_parameterA required parameter is absent.
400unknown_parameterA parameter name is not in the table above (typos are rejected, not ignored).
400invalid_parameterA value has the wrong type, is out of range, or is not an allowed value.
413payload_too_largeThe request body exceeds 1 MiB.
405method_not_allowedA method other than GET, POST or OPTIONS.

Behaviour

  • Idempotent: the same arguments always return the same result.
  • Requires a client ID and secret (authentication). Each call is recorded as one metadata row against your client ID; inputs and outputs are never stored or logged. Responses carry cache-control: no-store.
  • CORS: any origin may call this endpoint from a browser, using your credentials.

Examples

Responses below were produced by running each request through this code at build time. Long strings are shortened.

URL with duplicate query parameters and an encoded path

curl 'https://util.caruana.me/api/url/parse?input=https%3A%2F%2Fuser%40Example.COM%3A443%2Fa%2520b%2Fc%3Ftag%3Dx%26tag%3Dy%26q%3Dcaf%25C3%25A9%2Bau%2Blait%23top'

Response 200

{
  "href": "https://[email protected]/a%20b/c?tag=x&tag=y&q=caf%C3%A9+au+lait#top",
  "hrefRedacted": false,
  "resolvedAgainstBase": false,
  "protocol": "https:",
  "scheme": "https",
  "special": true,
  "username": {
    "raw": "user",
    "decoded": "user"
  },
  "hasPassword": false,
  "host": "example.com",
  "hostname": "example.com",
  "hostnameUnicode": "example.com",
  "hostType": "domain",
  "idn": false,
  "ip": null,
  "isLocalhost": false,
  "isPrivate": false,
  "isPublic": null,
  "port": null,
  "defaultPort": 443,
  "effectivePort": 443,
  "origin": "https://example.com",
  "pathname": "/a%20b/c",
  "opaquePath": false,
  "pathSegments": [
    {
      "raw": "a%20b",
      "decoded": "a b"
    },
    {
      "raw": "c",
      "decoded": "c"
    }
  ],
  "search": "?tag=x&tag=y&q=caf%C3%A9+au+lait",
  "query": [
    {
      "name": "tag",
      "value": "x",
      "rawName": "tag",
      "rawValue": "x"
    },
    {
      "name": "tag",
      "value": "y",
      "rawName": "tag",
      "rawValue": "y"
    },
    {
      "name": "q",
      "value": "café au lait",
      "rawName": "q",
      "rawValue": "caf%C3%A9+au+lait"
    }
  ],
  "hash": "#top",
  "fragment": {
    "raw": "top",
    "decoded": "top"
  },
  "warnings": [
    "The URL contains a username (userinfo).",
    "The explicit port 443 is the default for https: and was removed from the normalized URL."
  ]
}
Same call as an MCP tools/call
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "url_parse",
    "arguments": {
      "input": "https://[email protected]:443/a%20b/c?tag=x&tag=y&q=caf%C3%A9+au+lait#top"
    }
  }
}

Resolve a relative reference

curl 'https://util.caruana.me/api/url/parse?input=..%2Fimg%2Flogo.png%3Fv%3D2&base=https%3A%2F%2Fexample.com%2Fdocs%2Fguide%2F'

Response 200

{
  "href": "https://example.com/docs/img/logo.png?v=2",
  "hrefRedacted": false,
  "resolvedAgainstBase": true,
  "protocol": "https:",
  "scheme": "https",
  "special": true,
  "username": {
    "raw": "",
    "decoded": ""
  },
  "hasPassword": false,
  "host": "example.com",
  "hostname": "example.com",
  "hostnameUnicode": "example.com",
  "hostType": "domain",
  "idn": false,
  "ip": null,
  "isLocalhost": false,
  "isPrivate": false,
  "isPublic": null,
  "port": null,
  "defaultPort": 443,
  "effectivePort": 443,
  "origin": "https://example.com",
  "pathname": "/docs/img/logo.png",
  "opaquePath": false,
  "pathSegments": [
    {
      "raw": "docs",
      "decoded": "docs"
    },
    {
      "raw": "img",
      "decoded": "img"
    },
    {
      "raw": "logo.png",
      "decoded": "logo.png"
    }
  ],
  "search": "?v=2",
  "query": [
    {
      "name": "v",
      "value": "2",
      "rawName": "v",
      "rawValue": "2"
    }
  ],
  "hash": "",
  "fragment": null,
  "warnings": []
}
Same call as an MCP tools/call
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "url_parse",
    "arguments": {
      "input": "../img/logo.png?v=2",
      "base": "https://example.com/docs/guide/"
    }
  }
}

Private IPv6 host with a non-default port

curl 'https://util.caruana.me/api/url/parse?input=http%3A%2F%2F%5Bfd00%3A%3A1%5D%3A8080%2Fadmin'

Response 200

{
  "href": "http://[fd00::1]:8080/admin",
  "hrefRedacted": false,
  "resolvedAgainstBase": false,
  "protocol": "http:",
  "scheme": "http",
  "special": true,
  "username": {
    "raw": "",
    "decoded": ""
  },
  "hasPassword": false,
  "host": "[fd00::1]:8080",
  "hostname": "[fd00::1]",
  "hostnameUnicode": "[fd00::1]",
  "hostType": "ipv6",
  "idn": false,
  "ip": {
    "version": 6,
    "address": "fd00::1",
    "expanded": "fd00:0000:0000:0000:0000:0000:0000:0001",
    "range": "unique-local",
    "mappedIpv4": null
  },
  "isLocalhost": false,
  "isPrivate": true,
  "isPublic": false,
  "port": 8080,
  "defaultPort": 80,
  "effectivePort": 8080,
  "origin": "http://[fd00::1]:8080",
  "pathname": "/admin",
  "opaquePath": false,
  "pathSegments": [
    {
      "raw": "admin",
      "decoded": "admin"
    }
  ],
  "search": "",
  "query": [],
  "hash": "",
  "fragment": null,
  "warnings": []
}
Same call as an MCP tools/call
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "url_parse",
    "arguments": {
      "input": "http://[fd00::1]:8080/admin"
    }
  }
}