Skip to content

URL Parsing

The /url endpoint parses a URL into its structural components: scheme, host, port, path, query parameters, and fragment. Duplicate query parameters are grouped into an array.

Parameters

ParameterRequiredDescription
urlYesAbsolute URL to parse, including its scheme (e.g. https://example.com/path?a=1)

Default Ports

When the URL omits the port, the scheme's default port is returned:

SchemePort
ftp21
http80
https443
ws80
wss443

Any other scheme returns null.

Response Fields

FieldTypeDescription
urlstringThe original input URL
schemestringURL scheme without the trailing colon (e.g. https)
hoststringHostname
portnumber|nullPort number — the scheme's default port when the URL omits it, null if the scheme has no known default
pathstringPath component
paramsobjectQuery parameters — duplicate keys are grouped into an array
fragmentstringFragment identifier without the leading #
validbooleanAlways true for a successfully parsed URL

Code Examples

curl -X GET \
  "https://api.sylvain.sh/v5/url?url=https%3A%2F%2Fexample.com%2Fpath%3Ftag%3Djs%26tag%3Dts%23section"

Try It

Error Handling

If parameters are missing or invalid, the API will return an error:

Error MessageDescription
Please provide a URL (?url={URL})The url parameter is missing
URL cannot exceed 2048 charactersThe url exceeds the maximum length
Invalid URLThe url value cannot be parsed as a URL