uri (ex_stdlib v0.2.0)
View SourceURI parsing and manipulation module inspired by Elixir's URI module.
This module provides functions for parsing, manipulating, and encoding URIs. It handles the standard URI components: scheme, userinfo, host, port, path, query, and fragment.
Examples:
URI = uri:parse("https://user:pass@example.com:8080/path?query=value#fragment"),
EncodedPath = uri:encode("/hello world", :path),
QueryString = uri:encode_query([{name, "John Doe"}, {age, 30}]).
Summary
Functions
Decodes a percent-encoded string.
Decodes a query string into a list of key-value pairs.
Encodes a string for safe use in a URI component.
Encodes a list of key-value pairs into a query string.
Extracts the fragment from a URI.
Extracts the host from a URI.
Merges two URIs, with the second URI taking precedence.
Creates a new URI from the given components map.
Parses a URI string into a URI map.
Extracts the path from a URI.
Extracts the port from a URI.
Extracts the query from a URI.
Resolves a relative URI against a base URI.
Extracts the scheme from a URI.
Converts a URI map back to a string.
Extracts the userinfo from a URI.
Checks if a URI is valid according to basic URI syntax rules.
Types
-type component() :: scheme | userinfo | host | port | path | query | fragment.
-type encode_type() :: path | query | fragment | userinfo.
Functions
Decodes a percent-encoded string.
Decodes a query string into a list of key-value pairs.
Returns a list of {Key, Value} tuples where both are binaries.
-spec encode(string() | binary(), encode_type()) -> binary().
Encodes a string for safe use in a URI component.
The encoding type determines which characters are safe to leave unencoded.
Encodes a list of key-value pairs into a query string.
Keys and values are automatically percent-encoded.
Extracts the fragment from a URI.
Extracts the host from a URI.
Merges two URIs, with the second URI taking precedence.
Components from the second URI override those in the first URI.
Creates a new URI from the given components map.
Any missing components are set to undefined.
Parses a URI string into a URI map.
Returns a map with the URI components. Missing components are set to undefined.
Extracts the path from a URI.
Extracts the port from a URI.
Extracts the query from a URI.
Resolves a relative URI against a base URI.
Implements RFC 3986 reference resolution.
Extracts the scheme from a URI.
Converts a URI map back to a string.
Extracts the userinfo from a URI.
Checks if a URI is valid according to basic URI syntax rules.