Request
From UBot Studio
(Difference between revisions)
(Created page with "'''$request''' is a function that sends an HTTP request with specified parameters and returns the JSON response. It's a utility function to make HTTP requests to APIs. == Par...") |
|||
(One intermediate revision by one user not shown) | |||
Line 1: | Line 1: | ||
− | '''$request''' is a function that sends an HTTP request with specified parameters and returns the | + | '''$request''' is a function that sends an HTTP request with specified parameters and returns the response in yaml format. This allows you to work directly with any API you'd like. |
== Parameters == | == Parameters == | ||
Line 7: | Line 7: | ||
'''Method:''' The HTTP method to use for the request. The options are "GET", "POST", "PUT", "DELETE". | '''Method:''' The HTTP method to use for the request. The options are "GET", "POST", "PUT", "DELETE". | ||
− | '''Data:''' (optional) The data to send with the request. This | + | '''Data:''' (optional) The data to send with the request. This should be an object in yaml or json format. |
− | '''Headers:''' (optional) Any headers that should be sent with the request. This should be | + | '''Headers:''' (optional) Any headers that should be sent with the request. This should be an object in yaml or json format. |
== Return Value == | == Return Value == | ||
− | This function returns the server's response as a | + | This function returns the server's response as a yaml object. |
== Example == | == Example == | ||
<pre> | <pre> | ||
− | log($request("https://jsonplaceholder.typicode.com/posts", "POST", | + | ui console view |
+ | log($request("https://jsonplaceholder.typicode.com/posts","POST","title: test | ||
+ | body: content | ||
+ | userId: 1","Content-type: application/json; charset=UTF-8")) | ||
</pre> | </pre> | ||
The script above sends a "POST" request to the specified URL with the given data and headers. The server's response is then logged. | The script above sends a "POST" request to the specified URL with the given data and headers. The server's response is then logged. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− |
Latest revision as of 20:15, 12 July 2023
$request is a function that sends an HTTP request with specified parameters and returns the response in yaml format. This allows you to work directly with any API you'd like.
[edit] Parameters
URL: The URL to which the HTTP request is to be made.
Method: The HTTP method to use for the request. The options are "GET", "POST", "PUT", "DELETE".
Data: (optional) The data to send with the request. This should be an object in yaml or json format.
Headers: (optional) Any headers that should be sent with the request. This should be an object in yaml or json format.
[edit] Return Value
This function returns the server's response as a yaml object.
[edit] Example
ui console view log($request("https://jsonplaceholder.typicode.com/posts","POST","title: test body: content userId: 1","Content-type: application/json; charset=UTF-8"))
The script above sends a "POST" request to the specified URL with the given data and headers. The server's response is then logged.