Skip to content

Commit 14909d2

Browse files
Fix doc feedback issues for the HTTP client (#4034)
1 parent 69b09d5 commit 14909d2

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
local http_client = require('http.client')
2+
local response = http_client.get('https://httpbin.org/get')
3+
print('Status: '..response.status..' '.. response.reason)
4+
5+
local luatest = require('luatest')
6+
local test_group = luatest.group()
7+
test_group.test_returns_status = function()
8+
luatest.assert_equals(response.status, 200)
9+
end

doc/reference/reference_lua/http.rst

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,55 @@ The HTTP client uses the `libcurl <https://curl.haxx.se/libcurl/>`_ library unde
1212
takes into account the `environment variables <https://curl.haxx.se/libcurl/c/libcurl-env.html>`_ libcurl understands.
1313

1414

15+
.. _http_client_instance:
16+
17+
HTTP client instance
18+
--------------------
19+
20+
.. _http_client_instance_default:
21+
22+
Default client
23+
~~~~~~~~~~~~~~
24+
25+
The ``http.client`` submodule provides the default HTTP client instance:
26+
27+
.. literalinclude:: /code_snippets/test/http_client/default_client_get_test.lua
28+
:language: lua
29+
:lines: 1
30+
31+
In this case, you need to make requests using the dot syntax, for example:
32+
33+
.. literalinclude:: /code_snippets/test/http_client/default_client_get_test.lua
34+
:language: lua
35+
:lines: 2
36+
37+
1538
.. _creating_client:
1639

1740
Creating a client
18-
-----------------
41+
~~~~~~~~~~~~~~~~~
1942

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

2245
.. literalinclude:: /code_snippets/test/http_client/get_test.lua
2346
:language: lua
2447
:lines: 1
2548

26-
Optionally, this function can accept specific client configuration options.
49+
In this case, you need to make requests using the colon syntax, for example:
50+
51+
.. literalinclude:: /code_snippets/test/http_client/get_test.lua
52+
:language: lua
53+
:lines: 2
54+
55+
All the examples in this section use the HTTP client created using ``http.client.new()``.
2756

2857

2958
.. _making_requests:
3059

3160
Making requests
3261
---------------
3362

34-
After :ref:`creating the client <creating_client>`, you can make HTTP requests.
63+
The :ref:`client instance <http_client_instance>` enables you to make HTTP requests.
3564

3665
.. _request_http_method:
3766

@@ -685,7 +714,7 @@ client_object
685714

686715
* ``active_requests`` -- the number of currently executing requests
687716
* ``sockets_added`` -- the total number of sockets added into an event loop
688-
* ``sockets_deleted`` -- the total number of sockets from an event loop
717+
* ``sockets_deleted`` -- the total number of sockets deleted from an event loop
689718
* ``total_requests`` -- the total number of requests
690719
* ``http_200_responses`` -- the total number of requests that returned HTTP ``200 OK`` responses
691720
* ``http_other_responses`` -- the total number of requests that returned non-``200 OK`` responses

0 commit comments

Comments
 (0)