Module uri
URI stands for Uniform Resource Identifier - a sequence of characters that identifies a logical or physical resource. The IETF standard says a URI string looks like this:
[scheme:]scheme-specific-part[#fragment]
A common type, a hierarchical URI, looks like this:
[scheme:][//authority][path][?query][#fragment]
For example the string 'https://tarantool.org/x.html#y'
has three components:
https
is the scheme.tarantool.org/x.html
is the path.y
is the fragment.
Tarantool’s URI module provides functions that convert URI strings into their components, or turn components into URI strings.
Below is a list of all uri
functions.
Name | Use |
---|---|
uri.parse() | Get a table of URI components |
uri.format() | Construct a URI from components |
-
uri.
parse
(URI-string)¶ Parse a URI string into components. Possible components are:
fragment
host
ipv4
ipv6
login
password
path
query
scheme
service
unix
uri.parse()
is the reverse of uri.format().Parameters: - URI-string – a Uniform Resource Identifier
Return: URI components table.
Rtype: Table
Example:
tarantool> uri = require('uri') --- ... tarantool> uri.parse('scheme://login:password@host:service'.. '/path1/path2/path3?q1=v1&q2=v2&q3=v3:1|v3:2#fragment') --- - login: login params: q1: - v1 q2: - v2 q3: - v3:1|v3:2 service: service fragment: fragment password: password scheme: scheme query: q1=v1&q2=v2&q3=v3:1|v3:2 host: host path: /path1/path2/path3 ...
-
uri.
format
(URI-components-table[, include-password])¶ Form a URI string from its components. Possible components are:
fragment
host
ipv4
ipv6
login
password
path
query
scheme
service
unix
uri.format()
is the reverse of uri.parse().Parameters: - URI-components-table – a series of
name=value
pairs, one for each component - include-password – boolean. If this is supplied and is
true
, then the password component is rendered in clear text, otherwise it is omitted.
Return: URI string
Rtype: Example:
tarantool> uri.format({scheme='scheme', login='login', password='password', host='host', service='service', path='/path1/path2/path3', query='q1=v1&q2=v2&q3=v3'}) --- - scheme://login@host:service/path1/path2/path3 ...