update doc/*/scripting/builtins/libnetwork.md

This commit is contained in:
MihailRis 2026-09-14 20:06:09 +03:00
parent a773dfbd0e
commit 817092fef4
2 changed files with 67 additions and 1 deletions

View file

@ -4,6 +4,39 @@ A library for working with the network.
## HTTP requests
There is a configurable function `network.request` that allows performing HTTP requests with various methods (GET, POST, PUT, DELETE, etc.) and configuring headers, request body, timeout, and other parameters.
>[!NOTE] To pass binary data in the request body, use a byte array (Bytearray) or a string. In `on_response`, the `body` string can be converted to a byte array using `Bytearray(response.body)`.
```lua
network.request(
url: string,
parameters: {
-- Request method (GET, POST, PUT, DELETE, etc.)
method: string,
-- Request body as a string or Bytearray
body: table|string,
-- List of additional request headers
headers: table<string>,
-- Timeout in milliseconds
timeout: int,
-- Whether to verify the SSL certificate
verify_ssl: boolean,
-- Function called when a response is received
on_response: function(response: {
-- HTTP response status code
status: int,
-- Response body as a string
body: string,
-- List of response headers
headers: table<string>
}),
}
)
```
### Simplified functions for GET and POST requests
```lua
-- Performs a GET request to the specified URL.
network.get(

View file

@ -4,6 +4,39 @@
## HTTP-Запросы
Существует настраиваемая функция `network.request`, которая позволяет выполнять HTTP-запросы с различными методами (GET, POST, PUT, DELETE и т.д.) и настраивать заголовки, тело запроса, таймаут и другие параметры.
>[!NOTE] Для передачи двоичных данных в теле запроса, используйте массив байт (Bytearray) или строку. В `on_response` строку `body` можно преобразовать в массив байт с помощью `Bytearray(response.body)`.
```lua
network.request(
url: string,
parameters: {
-- Метод запроса (GET, POST, PUT, DELETE и т.д.)
method: string,
-- Тело запроса в виде строки или массива байт (Bytearray)
body: table|string,
-- Список дополнительных заголовков запроса
headers: table<string>,
-- Таймаут в миллисекундах
timeout: int,
-- Проверять ли SSL-сертификат
verify_ssl: boolean,
-- Функция, вызываемая при получении ответа
on_response: function(response: {
-- HTTP-код ответа
status: int,
-- Тело ответа в виде строки
body: string,
-- Список заголовков ответа
headers: table<string>
}),
}
)
```
### Упрощённые функции для GET и POST запросов
```lua
-- Выполняет GET запрос к указанному URL.
network.get(