Skip to content

HTTP (Requests)

Interact with HTTP endpoints and APIs. Perform operations such as GET, POST and more.

Installation

pip install botcity-http-plugin

Importing the Plugin

After you installed this package, the next step is to import the package into your code and start using the functions.

from botcity.plugins.http import BotHttpPlugin

Performing a Request

GET

# Instantiate the plugin
url = "https://ptsv2.com/t/ocrc3-1624379671/post"
http = BotHttpPlugin(url)

# Perform a simple GET request
print(http.get().text)

Tip

Alternativelly you can use the get_as_json, get_bytes and get_as_file methods for specialized handling of the response.

POST

# Instantiate the plugin
url = "https://ptsv2.com/t/ocrc3-1624379671/post"
http = BotHttpPlugin(url)

# Sets the parameters for a POST request
params = {
    'id': 'ocrc3-1624379671',
    'text': 'POST Example'
}
http.set_params(params)

# Perform a POST request with parameters
print(http.post().text)

Tip

Alternativelly you can use the post_as_json method.