update doc/*/scripting/builtins/libnetwork.md
This commit is contained in:
parent
9871bf1292
commit
40543128d0
@ -6,9 +6,15 @@ A library for working with the network.
|
||||
|
||||
```lua
|
||||
-- Performs a GET request to the specified URL.
|
||||
-- After receiving the response, passes the text to the callback function.
|
||||
-- In case of an error, the HTTP response code will be passed to onfailure.
|
||||
network.get(url: str, callback: function(str), [optional] onfailure: function(int))
|
||||
network.get(
|
||||
url: str,
|
||||
-- Function to call when response is received
|
||||
callback: function(str),
|
||||
-- Error handler
|
||||
[optional] onfailure: function(int),
|
||||
-- List of additional request headers
|
||||
[optional] headers: table<string>
|
||||
)
|
||||
|
||||
-- Example:
|
||||
network.get("https://api.github.com/repos/MihailRis/VoxelEngine-Cpp/releases/latest", function (s)
|
||||
@ -16,13 +22,28 @@ network.get("https://api.github.com/repos/MihailRis/VoxelEngine-Cpp/releases/lat
|
||||
end)
|
||||
|
||||
-- A variant for binary files, with a byte array instead of a string in the response.
|
||||
network.get_binary(url: str, callback: function(table|ByteArray), [optional] onfailure: function(int))
|
||||
network.get_binary(
|
||||
url: str,
|
||||
callback: function(table|ByteArray),
|
||||
[optional] onfailure: function(int),
|
||||
[optional] headers: table<string>
|
||||
)
|
||||
|
||||
-- Performs a POST request to the specified URL.
|
||||
-- Currently, only `Content-Type: application/json` is supported
|
||||
-- After receiving the response, passes the text to the callback function.
|
||||
-- In case of an error, the HTTP response code will be passed to onfailure.
|
||||
network.post(url: str, data: table, callback: function(str), [optional] onfailure: function(int))
|
||||
network.post(
|
||||
url: str,
|
||||
-- Request body as a table (will be converted to JSON) or string
|
||||
body: table|string,
|
||||
-- Function called when response is received
|
||||
callback: function(str),
|
||||
-- Error handler
|
||||
[optional] onfailure: function(int),
|
||||
-- List of additional request headers
|
||||
[optional] headers: table<string>
|
||||
)
|
||||
```
|
||||
|
||||
## TCP Connections
|
||||
|
||||
@ -6,9 +6,15 @@
|
||||
|
||||
```lua
|
||||
-- Выполняет GET запрос к указанному URL.
|
||||
-- После получения ответа, передаёт текст в функцию callback.
|
||||
-- В случае ошибки в onfailure будет передан HTTP-код ответа.
|
||||
network.get(url: str, callback: function(str), [опционально] onfailure: function(int))
|
||||
network.get(
|
||||
url: str,
|
||||
-- Функция, вызываемая при получении ответа
|
||||
callback: function(str),
|
||||
-- Обработчик ошибок
|
||||
[опционально] onfailure: function(int),
|
||||
-- Список дополнительных заголовков запроса
|
||||
[опционально] headers: table<string>
|
||||
)
|
||||
|
||||
-- Пример:
|
||||
network.get("https://api.github.com/repos/MihailRis/VoxelEngine-Cpp/releases/latest", function (s)
|
||||
@ -16,13 +22,28 @@ network.get("https://api.github.com/repos/MihailRis/VoxelEngine-Cpp/releases/lat
|
||||
end)
|
||||
|
||||
-- Вариант для двоичных файлов, с массивом байт вместо строки в ответе.
|
||||
network.get_binary(url: str, callback: function(table|ByteArray), [опционально] onfailure: function(int))
|
||||
network.get_binary(
|
||||
url: str,
|
||||
callback: function(table|ByteArray),
|
||||
[опционально] onfailure: function(int),
|
||||
[опционально] headers: table<string>
|
||||
)
|
||||
|
||||
-- Выполняет POST запрос к указанному URL.
|
||||
-- На данный момент реализована поддержка только `Content-Type: application/json`
|
||||
-- После получения ответа, передаёт текст в функцию callback.
|
||||
-- В случае ошибки в onfailure будет передан HTTP-код ответа.
|
||||
network.post(url: str, data: table, callback: function(str), [опционально] onfailure: function(int))
|
||||
network.post(
|
||||
url: str,
|
||||
-- Тело запроса в виде таблицы, конвертируемой в JSON или строки
|
||||
body: table|string,
|
||||
-- Функция, вызываемая при получении ответа
|
||||
callback: function(str),
|
||||
-- Обработчик ошибок
|
||||
[опционально] onfailure: function(int),
|
||||
-- Список дополнительных заголовков запроса
|
||||
[опционально] headers: table<string>
|
||||
)
|
||||
```
|
||||
|
||||
## TCP-Соединения
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user