Skip to main content

HTTP adapter for Interposition.

Project description

interposition-http-adapter

HTTP adapter for Interposition. Serves recorded HTTP interactions from an Interposition Cassette as a real HTTP server, allowing you to replay captured API responses for testing and development.

Installation

pip install interposition-http-adapter

Usage

InterpositionHttpAdapter is an ASGI application (based on Starlette) that replays HTTP interactions through an Interposition Broker.

from interposition import (
    Broker,
    Cassette,
    Interaction,
    InteractionRequest,
    ResponseChunk,
)
import uvicorn

from interposition_http_adapter import InterpositionHttpAdapter

# 1. Build an InteractionRequest describing the HTTP request to match
request = InteractionRequest(
    protocol="http",
    action="GET",
    target="/api/data",
    headers=(),
    body=b"",
)

# 2. Build ResponseChunks with status_code in the first chunk's metadata
response_chunks = (
    ResponseChunk(
        data=b'{"message": "hello"}',
        sequence=0,
        metadata=(("status_code", "200"),),
    ),
)

# 3. Create a Cassette containing the interaction
interaction = Interaction(
    request=request,
    fingerprint=request.fingerprint(),
    response_chunks=response_chunks,
)
cassette = Cassette(interactions=(interaction,))

# 4. Create a Broker in replay mode
broker = Broker(cassette=cassette, mode="replay")

# 5. Create the adapter and serve it
app = InterpositionHttpAdapter(broker=broker)
uvicorn.run(app, host="127.0.0.1", port=8000)

Once the server is running, a GET request to http://127.0.0.1:8000/api/data returns the recorded response with status code 200 and body {"message": "hello"}. The adapter supports all standard HTTP methods (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS). Requests that do not match any recorded interaction return a 500 Internal Server Error response.

API Reference

Detailed documentation is available in MkDocs: https://osoekawaitlab.github.io/interposition-http-adapter/.

CLI

The package provides a command-line interface:

interposition_http_adapter --version

License

MIT

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

interposition_http_adapter-0.2.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

interposition_http_adapter-0.2.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file interposition_http_adapter-0.2.0.tar.gz.

File metadata

File hashes

Hashes for interposition_http_adapter-0.2.0.tar.gz
Algorithm Hash digest
SHA256 778479efc2d21d2e96b988124f075eb4f643b85618b85c44c54868f4da88dc76
MD5 2860bebb8fd345b70f49c21bfd7d95bf
BLAKE2b-256 bd719314ac71ac2d3f0d2bb11fa3560091daebde4d8410a72782f786d8ae3319

See more details on using hashes here.

Provenance

The following attestation bundles were made for interposition_http_adapter-0.2.0.tar.gz:

Publisher: release.yml on osoekawaitlab/interposition-http-adapter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file interposition_http_adapter-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for interposition_http_adapter-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3471a13e38474de2d6c21fe00d447f30947b152c4694ebc542694dff0b8aad60
MD5 2820249e3a7bec6488cc0ab5259ec7ea
BLAKE2b-256 22b49894907e30bc1ecb758c9b99c315e6c1297c11895f0b370c4683b3b3f3a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for interposition_http_adapter-0.2.0-py3-none-any.whl:

Publisher: release.yml on osoekawaitlab/interposition-http-adapter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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