Skip to content

Extend uri functions descriptions #3165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 61 additions & 14 deletions doc/reference/reference_lua/uri.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
Overview
===============================================================================

A "URI" is a "Uniform Resource Identifier".
*URI* stands for *Uniform Resource Identifier* - a sequence of characters that
identifies a logical or physical resource.
The `IETF standard <https://www.ietf.org/rfc/rfc2396.txt>`_
says a URI string looks like this:

Expand All @@ -23,11 +24,11 @@ A common type, a hierarchical URI, looks like this:
For example the string ``'https://tarantool.org/x.html#y'``
has three components:

* ``https`` is the scheme,
* ``tarantool.org/x.html`` is the path,
* ``https`` is the scheme.
* ``tarantool.org/x.html`` is the path.
* ``y`` is the fragment.

Tarantool's URI module provides routines which convert URI strings into their
Tarantool's URI module provides functions that convert URI strings into their
components, or turn components into URI strings.

===============================================================================
Expand Down Expand Up @@ -57,9 +58,25 @@ Below is a list of all ``uri`` functions.

.. function:: 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 :ref:`uri.format() <uri-format>`.

:param URI-string: a Uniform Resource Identifier
:return: URI-components-table. Possible components are fragment, host,
login, password, path, query, scheme, service.
:return: URI components table.

:rtype: Table

**Example:**
Expand All @@ -70,31 +87,61 @@ Below is a list of all ``uri`` functions.
---
...

tarantool> uri.parse('http://x.html#y')
tarantool> uri.parse('scheme://login:password@host:service'..
'/path1/path2/path3?q1=v1&q2=v2&q3=v3:1|v3:2#fragment')
---
- host: x.html
scheme: http
fragment: y
- 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:

.. function:: format(URI-components-table[, include-password])

:param URI-components-table: a series of name:value pairs, one for each
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 :ref:`uri.parse() <uri-parse>`.

:param URI-components-table: a series of ``name=value`` pairs, one for each
component
:param 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. Thus uri.format() is the reverse of uri.parse().
:return: URI string
:rtype: string

**Example:**

.. code-block:: tarantoolsession

tarantool> uri.format({host = 'x.html', scheme = 'http', fragment = 'y'})
tarantool> uri.format({scheme='scheme', login='login', password='password', host='host',
service='service', path='/path1/path2/path3', query='q1=v1&q2=v2&q3=v3'})
---
- http://x.html#y
- scheme://login@host:service/path1/path2/path3
...