Getting Started
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
As a demonstration of the library, let's build a simple example together that will do something cool .
Step 1 of Example
To make the example we will...
# Instantiate the plugin
url = "https://ptsv2.com/t/ocrc3-1624379671/post"
http = BotHttpPlugin(url)
# Perform a simple GET request
print(http.get().text)
...
Step 2 of Example
# Set the parameters for a POST request
params = {
'id': 'ocrc3-1624379671',
'text': 'POST Example'
}
http.set_params(params)
# Print the server response
print(http.post().text)
...
Complete code
Let's take a look into the complete code:
from botcity.plugins.http import BotHttpPlugin
# Instantiates the plugin
url = "https://ptsv2.com/t/ocrc3-1624379671/post"
http = BotHttpPlugin(url)
# Performs a simple GET request
print(http.get().text)
# Sets the parameters for a POST request
params = {
'id': 'ocrc3-1624379671',
'text': 'POST Example'
}
http.set_params(params)
# Prints the server response
print(http.post().text)
Pro Tip
This plugin allow you to use method chaining
so the code above could be written as:
http = BotHttpPlugin("https://ptsv2.com/t/ocrc3-1624379671/post")
print(http.get().text)
print(http.set_param('id', 'ocrc3-1624379671').set_param('text', 'POST Example').post().text)
Next Steps
Check our examples and experiment with the API. Let us know where it can be improved.
Have fun automating!