What does a URL parser do?
A URL looks like one string, but it is really a set of parts with different jobs: the protocol (https:), optional credentials (user:password@), the host, an optional port, the path, the query string after ? and the fragment after #. The structure comes from RFC 3986, and browsers read addresses with the rules of the WHATWG URL Standard. A URL parser splits the string into those parts so you can read each one instead of counting characters by eye.
You reach for one when something is wrong and the address is long. A tracking link with twelve utm_ parameters, an OAuth callback whose redirect_uri is itself a URL, a signed link from a storage service, a redirect that loses a parameter on the way: in all of them you need to know which part holds what, and what the value is after percent-decoding. This parser also shows the readable form next to anything encoded, so caf%C3%A9 appears as café and an internationalised host such as xn--r8jz45g.xn--zckzah appears as 例え.テスト.
It works on the address you paste, in your browser; nothing is requested or sent, so it is safe for links that carry tokens (though you should still treat such a link as a secret). The page opens with an example URL loaded, and you can also arrive here from other tools that hand a URL over to it.
How to break a URL into its parts
- Paste the address in the URL field. Parsing happens as you type, and the parts appear right under the field.
- If you leave out the protocol (
example.com/path), the tool assumeshttps://and says so in a note above the parts, so you know that was added. - Read the property list: protocol, username, password, hostname, port, path, query and fragment. When a value contains percent escapes or punycode, a Readable line shows the decoded version below it. An empty port means the default for the protocol (443 for https, 80 for http), which URLs leave out.
- Below the properties, the Query parameters list shows each key with its values, already decoded. A key that appears more than once (
tag=a&tag=b) or that uses brackets (list[]=1&list[]=2) is grouped and marked as an array, with its values numbered in order. - If the fragment looks like a query (
#access_token=...&expires_in=3600), it is also read into Fragment parameters. Single-page apps and OAuth implicit flows put their data there. - Each value has its own copy button.
Examples
A URL with credentials, port, arrays and a fragment
https://me:pwd@stdlib.tools:3000/url-parser?key1=value&tag=a&tag=b&list[]=1&list[]=2#the-hashParts: protocol https:, username me, password pwd, hostname stdlib.tools, port 3000, path /url-parser, fragment the-hash. The query gives key1 with value, and two arrays: tag with a, b and list with 1, 2.
A search link with percent escapes and plus signs
https://example.com/search?q=caf%C3%A9+com+leite&page=2&utm_source=news%20letterThe query reads ?q=café com leite&page=2&utm_source=news letter in the Readable line. In a query string + means a space and %C3%A9 is the UTF-8 encoding of é. To go from text to that form, use URL encoding.
An OAuth callback with the data in the fragment
https://app.example.com/callback#access_token=abc123&token_type=bearer&expires_in=3600There is no query, but the fragment is shown as three parameters: access_token, token_type and expires_in. If the token is a JWT, you can read it with the JWT decoder.
An address typed without protocol and an international domain
example.com:8080/path is read as https://example.com:8080/path with the note that https was assumed. https://xn--r8jz45g.xn--zckzah/%E3%83%91%E3%82%B9 shows the host as 例え.テスト and the path as /パス.
Common errors and how to fix them
- Invalid URL. Paste the full address (for example https://example.com/path) and check for spaces or a missing host.: the text cannot be read as an address. Typical causes are
http://with nothing after it, a space inside the host, or text that is not a URL at all. - The password or token seems to be missing from the path or query: it may be percent-encoded. Look at the Readable line, which shows it decoded.
- A parameter is repeated and you expected one value: the tool shows every value of a repeated key. What your server keeps (the first, the last, a list) depends on the framework; the safest is to avoid repeating keys unless you mean an array.
- The fragment does not appear on the server: browsers never send the part after
#in the request. If your backend needs that data, it has to come in the query or in the body. - A URL copied from an email has extra characters at the end: a trailing period, comma or parenthesis is often not part of the link. Remove it and parse again.
- Wrapped links are hard to read: if the real destination is hidden inside another URL, use the Outlook SafeLink decoder to extract it.
Frequently asked questions
What are the parts of a URL?
Protocol (scheme), credentials, host, port, path, query and fragment. Only the protocol and the host are essential for most URLs; the rest are optional.
What is the difference between the query and the fragment?
The query (after ?) is sent to the server and is part of the request. The fragment (after #) stays in the browser: it points to a place in the page or carries state for a script, and it is not included in the HTTP request.
What is the origin of a URL?
The combination of protocol, host and port, such as https://stdlib.tools:3000. Browsers use it to decide which pages may read each other's data. Path, query and fragment are not part of it.
Can a URL have more than one value for the same parameter?
Yes. ?tag=a&tag=b is valid, and so is the bracket style ?list[]=1&list[]=2 used by PHP and Rails. The parser groups both as an array so you can see all the values at once. If you want a random free port for a local test server, try the random port generator.
Doing it in code
JavaScript
const url = new URL('https://me:pwd@stdlib.tools:3000/url-parser?key1=value&tag=a&tag=b#the-hash');
console.log(url.hostname, url.port, url.hash); // stdlib.tools 3000 #the-hash
console.log(url.searchParams.getAll('tag')); // [ 'a', 'b' ]Python
from urllib.parse import urlsplit, parse_qs
u = urlsplit('https://me:pwd@stdlib.tools:3000/url-parser?key1=value&tag=a&tag=b#the-hash')
print(u.scheme, u.username, u.password, u.hostname, u.port, u.path, u.fragment)
# https me pwd stdlib.tools 3000 /url-parser the-hash
print(parse_qs(u.query))
# {'key1': ['value'], 'tag': ['a', 'b']}Go
package main
import (
"fmt"
"net/url"
)
func main() {
u, _ := url.Parse("https://me:pwd@stdlib.tools:3000/url-parser?key1=value&tag=a&tag=b#the-hash")
fmt.Println(u.Scheme, u.User.Username(), u.Hostname(), u.Port(), u.Path, u.Fragment)
fmt.Println(u.Query()["tag"]) // [a b]
}