In this document, we walk through a Python script that demonstrates how to use the Polywrap client with HTTP plugin to send HTTP requests.
To start, we import the required modules and functions:
from polywrap import (
Uri,
PolywrapClient,
PolywrapClientConfigBuilder,
http_plugin
)Before making HTTP requests, we set up the configuration for the Polywrap client:
config_builder = PolywrapClientConfigBuilder()config_builder.set_package(Uri.from_str("wrapscan.io/polywrap/[email protected]"), http_plugin())config = config_builder.build()With our configuration ready, we instantiate the Polywrap client:
client = PolywrapClient(config)Using the Polywrap client, we send a GET request:
get_response = client.invoke(
uri=Uri.from_str("wrapscan.io/polywrap/[email protected]"),
method="get",
args={
"url": "https://jsonplaceholder.typicode.com/posts/1",
},
)
print(get_response)
assert get_response["status"] == 200Similarly, we send a POST request:
post_response = client.invoke(
uri=Uri.from_str("wrapscan.io/polywrap/[email protected]"),
method="post",
args={
"url": "https://jsonplaceholder.typicode.com/posts",
"body": {
"id": 101,
"userId": 101,
"title": "Test Title",
"body": "Test Body",
},
},
)
print(post_response)
assert post_response["status"] == 201This document provides a brief walkthrough of how to use the Polywrap
client with the HTTP plugin to make GET and POST requests.
For more information on the PolywrapClient, please refer to the
Polywrap Python Client documentation.