Skip to main content

No project description provided

Project description

This package contains the HTTP plugin.

Http plugin currently supports two different methods GET and POST. Similar to calling axios, when defining request you need to specify a response type. Headers and query parameters may also be defined.

Response Types

TEXT - The server will respond with text, the HTTP plugin will return the text as-is.

BINARY - The server will respond with binary data (_bytes_), the HTTP plugin will encode as a base64 string and return it.

Quickstart

Imports

>>> import json
>>> from polywrap_core import Uri
>>> from polywrap_client import PolywrapClient
>>> from polywrap_client_config_builder import PolywrapClientConfigBuilder
>>> from polywrap_http_plugin import http_plugin
>>> from polywrap_msgpack import GenericMap

Create a Polywrap client

>>> http_interface_uri = Uri.from_str("wrap://ens/wraps.eth:http@1.0.0")
>>> http_plugin_uri = Uri.from_str("plugin/http")
>>> config = (
...     PolywrapClientConfigBuilder()
...     .set_package(http_plugin_uri, http_plugin())
...     .add_interface_implementations(http_interface_uri, [http_plugin_uri])
...     .set_redirect(http_interface_uri, http_plugin_uri)
...     .build()
... )
>>> client = PolywrapClient(config)

Make a GET request

>>> result = client.invoke(
...     uri=http_interface_uri,
...     method="get",
...     args={
...         "url": "https://jsonplaceholder.typicode.com/posts",
...         "request": {
...             "responseType": "TEXT",
...             "urlParams": GenericMap({"id": 1}),
...             "headers": GenericMap({"X-Request-Header": "req-foo"}),
...         },
...     }
... )
>>> result.get("status")
200

Make a POST request

>>> result = client.invoke(
...     uri=http_interface_uri,
...     method="post",
...     args={
...         "url": "https://jsonplaceholder.typicode.com/posts",
...         "request": {
...             "responseType": "TEXT",
...             "body": json.dumps({
...                 "userId": 11,
...                 "id": 101,
...                 "title": "foo",
...                 "body": "bar"
...             }),
...             "headers": GenericMap({"X-Request-Header": "req-foo"}),
...         },
...     }
... )
>>> result.get("status")
201

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polywrap_http_plugin-0.1.0b6.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

polywrap_http_plugin-0.1.0b6-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file polywrap_http_plugin-0.1.0b6.tar.gz.

File metadata

  • Download URL: polywrap_http_plugin-0.1.0b6.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.12 Linux/5.15.0-1042-azure

File hashes

Hashes for polywrap_http_plugin-0.1.0b6.tar.gz
Algorithm Hash digest
SHA256 e1a5b1413f537eaf6732fa3e834b7bee6131413d8b0a0a23b3fb5d02f580e4db
MD5 faf3c70661ccb2db91cddb7b47657c91
BLAKE2b-256 8b72651ef2974dc019abf1de6965e726375cf9afe977e347b25ec6df2c6e5c7d

See more details on using hashes here.

Provenance

File details

Details for the file polywrap_http_plugin-0.1.0b6-py3-none-any.whl.

File metadata

File hashes

Hashes for polywrap_http_plugin-0.1.0b6-py3-none-any.whl
Algorithm Hash digest
SHA256 dd14e353d8b8eb363494fef5b47ba52bd08bab53e35c95e9f1b8f02b23139f32
MD5 1588f7f535d70c4b26fc17a0181aa253
BLAKE2b-256 52ad3c787e70cb0267779416e1c4bae4c88163da8ba7fcac51471755ea93d475

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page