Request

From UBot Studio
Revision as of 20:12, 12 July 2023 by LillyT (Talk | contribs)

Jump to: navigation, search

$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

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.

Return Value

This function returns the server's response as a yaml object.

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.

Please note that the function may fail if the server doesn't exist, the server doesn't respond, or if the response is not JSON.

It might be wise to catch any errors that occur when using the $request function and handle them appropriately in your script.

For example, the function will throw an error if the response cannot be parsed as JSON, so you can use a 'try-catch' block to handle this error in your script.

Remember: When using an API, ensure you are authorized to use it, understand the cost that may be associated with its use and are obeying all its usage policies and guidelines.

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox