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.
Creating from a Cassette file
If you have a Cassette saved as a JSON file, you can create an adapter directly:
import uvicorn
from interposition_http_adapter import InterpositionHttpAdapter
app = InterpositionHttpAdapter.from_cassette_file("fixtures/api.json")
uvicorn.run(app, host="127.0.0.1", port=8000)
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file interposition_http_adapter-0.3.0.tar.gz.
File metadata
- Download URL: interposition_http_adapter-0.3.0.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b4fa9ee905b856a09acb981042b894573c80a8a585ea9e5f2baeb00978fa704
|
|
| MD5 |
d303df4a60232670c801483bb6c515ef
|
|
| BLAKE2b-256 |
9855706ad2bdcac58f55f2ca056d1201ab20957db32d6bbfeeea47e8985399fb
|
Provenance
The following attestation bundles were made for interposition_http_adapter-0.3.0.tar.gz:
Publisher:
release.yml on osoekawaitlab/interposition-http-adapter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
interposition_http_adapter-0.3.0.tar.gz -
Subject digest:
6b4fa9ee905b856a09acb981042b894573c80a8a585ea9e5f2baeb00978fa704 - Sigstore transparency entry: 985364150
- Sigstore integration time:
-
Permalink:
osoekawaitlab/interposition-http-adapter@f95d02549b7ac703bd66d0bbc5064af3c8def0ff -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/osoekawaitlab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f95d02549b7ac703bd66d0bbc5064af3c8def0ff -
Trigger Event:
push
-
Statement type:
File details
Details for the file interposition_http_adapter-0.3.0-py3-none-any.whl.
File metadata
- Download URL: interposition_http_adapter-0.3.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2174cc1bf793e2e9c143757c33fea9df2cc8b66731f293b561e1236e005e11c
|
|
| MD5 |
ee1b9efd86f344a7c743112f1ee48cef
|
|
| BLAKE2b-256 |
d7579f1338b15780ea37cbf67e261ea0673b242c176d94ad75fbc7cf8741f9c5
|
Provenance
The following attestation bundles were made for interposition_http_adapter-0.3.0-py3-none-any.whl:
Publisher:
release.yml on osoekawaitlab/interposition-http-adapter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
interposition_http_adapter-0.3.0-py3-none-any.whl -
Subject digest:
d2174cc1bf793e2e9c143757c33fea9df2cc8b66731f293b561e1236e005e11c - Sigstore transparency entry: 985364155
- Sigstore integration time:
-
Permalink:
osoekawaitlab/interposition-http-adapter@f95d02549b7ac703bd66d0bbc5064af3c8def0ff -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/osoekawaitlab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f95d02549b7ac703bd66d0bbc5064af3c8def0ff -
Trigger Event:
push
-
Statement type: