Skip to content

Commit

Permalink
Document the default client
Browse files Browse the repository at this point in the history
  • Loading branch information
andreyaksenov committed Feb 7, 2024
1 parent fcc1f05 commit 3ac6f5b
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions doc/reference/reference_lua/http.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,47 @@ The HTTP client uses the `libcurl <https://curl.haxx.se/libcurl/>`_ library unde
takes into account the `environment variables <https://curl.haxx.se/libcurl/c/libcurl-env.html>`_ libcurl understands.


.. _http_client_instance:

HTTP client instance
--------------------

.. _http_client_instance_default:

Default client
~~~~~~~~~~~~~~

The ``http.client`` submodule provides the default HTTP client instance:

.. literalinclude:: /code_snippets/test/http_client/default_client_get_test.lua
:language: lua
:lines: 1

In this case, you need to make requests using the dot syntax, for example:

.. literalinclude:: /code_snippets/test/http_client/default_client_get_test.lua
:language: lua
:lines: 2


.. _creating_client:

Creating a client
-----------------
~~~~~~~~~~~~~~~~~

To create an HTTP client, call the :ref:`http.client.new() <http-new>` function:
If you need to configure specific HTTP client options, use the :ref:`http.client.new() <http-new>` function to create the client instance:

.. literalinclude:: /code_snippets/test/http_client/get_test.lua
:language: lua
:lines: 1

Optionally, this function can accept specific client configuration options.
In this case, you need to make requests using the colon syntax, for example:

.. literalinclude:: /code_snippets/test/http_client/get_test.lua
:language: lua
:lines: 2

All the examples in this section use the HTTP client created using ``http.client.new()``.


.. _making_requests:
Expand Down

0 comments on commit 3ac6f5b

Please sign in to comment.