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(