URL
url parseurl buildurl resolveurl normalize

url parse <url>


Description

    The parts of an URL (only the present ones): scheme, host, port, user, pass, path, query, query_params (a[]=1&b[k]=2 as JSON, + is a space), fragment

Parameters

    url:   The URL - String - required
admin
url parse "https://etl:secret@api.example.com:8443/v1/orders?status=open&tag[]=a&tag[]=b&q=caf%C3%A9+cr%C3%A8me#page2"
mentdb
{"scheme": "https", "host": "api.example.com", "port": 8443, "user": "etl", "pass": "secret", "path": "/v1/orders", "query": "status=open&tag[]=a&tag[]=b&q=caf%C3%A9+cr%C3%A8me", "query_params": {"status": "open", "tag": ["a", "b"], "q": "café crème"}, "fragment": "page2"}
A relative URL
admin
url parse "/v1/orders?page=2"
mentdb
{"path": "/v1/orders", "query": "page=2", "query_params": {"page": "2"}}
IPv6
admin
url parse "http://[2001:db8::1]:8080/health"
mentdb
{"scheme": "http", "host": "[2001:db8::1]", "port": 8080, "path": "/health"}
Used in use cases (1 recipe)

    Web & API developer › Clean the links of a page: parse, resolve the relative links, normalize to remove duplicates
Often used with

    array unique  ·  json doc  ·  json iarray  ·  url normalize  ·  url resolve

url build <json_parts>


Description

    Build an URL from its parts (the inverse of url parse); query_params is encoded like PHP http_build_query (a[0]=x, spaces as %20); user, pass, path, query and fragment are percent-encoded where needed (a valid %XX is kept, / stays in the path)

Parameters

    json_parts:   The parts - String - required
admin
url build "{\"scheme\": \"https\", \"host\": \"api.example.com\", \"path\": \"/v1/search\", \"query_params\": {\"q\": \"café crème\", \"tags\": [\"a\", \"b\"], \"page\": 2}}"
mentdb
https://api.example.com/v1/search?q=caf%C3%A9%20cr%C3%A8me&tags%5B0%5D=a&tags%5B1%5D=b&page=2

url resolve <base_url> <relative_url>


Description

    The absolute URL of a link found in a page (RFC 3986 section 5)

Parameters

    base_url:   The URL of the page - String - required
    relative_url:   The link - String - required
admin
url resolve "https://www.example.com/docs/guide/index.html" "../api/v2.html?x=1"
mentdb
https://www.example.com/docs/api/v2.html?x=1
Same host
admin
url resolve "https://www.example.com/docs/guide/" "/download"
mentdb
https://www.example.com/download
Other host, same scheme
admin
url resolve "https://www.example.com/docs/" "//cdn.example.com/lib.js"
mentdb
https://cdn.example.com/lib.js
Used in use cases (1 recipe)

    Web & API developer › Clean the links of a page: parse, resolve the relative links, normalize to remove duplicates
Often used with

    array unique  ·  json doc  ·  json iarray  ·  url normalize  ·  url parse

url normalize <url>


Description

    The normal form of an URL (RFC 3986 section 6): scheme and host in lower case, default port removed, . and .. removed (only for an absolute URL or path: a relative reference such as ../img/a.png keeps them), %XX in upper case, the encoded unreserved characters decoded

Parameters

    url:   The URL - String - required
admin
url normalize "HTTPS://WWW.Example.COM:443/a/./b/../c/%7euser?q=%2f"
mentdb
https://www.example.com/a/c/~user?q=%2F
Used in use cases (1 recipe)

    Web & API developer › Clean the links of a page: parse, resolve the relative links, normalize to remove duplicates
Often used with

    array unique  ·  json doc  ·  json iarray  ·  url parse  ·  url resolve