Skip to content

Http Proxy

Http Proxy to be used as provider url in verifier.

Attributes

PROXY_PORT = 1234 module-attribute

UVICORN_LOGGING_LEVEL = 'error' module-attribute

app = FastAPI() module-attribute

items = {'states': None} module-attribute

log = logging.getLogger(__name__) module-attribute

Functions

ping()

Check whether the server is available before setting up states.

Source code in src/pact/http_proxy.py
@app.get('/ping', status_code=status.HTTP_200_OK)
def ping():
    """Check whether the server is available before setting up states."""
    return {"ping": "pong"}

root(request: Request) async

Match states with provided message handlers.

Source code in src/pact/http_proxy.py
@app.post("/")
async def root(request: Request):
    """Match states with provided message handlers."""
    payload = await request.json()
    message = _match_states(payload)
    return {'contents': message}

run_proxy()

Rub HTTP Proxy.

Source code in src/pact/http_proxy.py
def run_proxy():
    """Rub HTTP Proxy."""
    warnings.warn(
        "This class will be deprecated Pact Python v3 "
        "(see pact-foundation/pact-python#396)",
        PendingDeprecationWarning,
        stacklevel=2,
    )
    uvicorn.run("pact.http_proxy:app", port=PROXY_PORT, log_level=UVICORN_LOGGING_LEVEL)

setup(request: Request) async

Endpoint to setup states.

Use localstack to store payload.

Source code in src/pact/http_proxy.py
@app.post("/setup", status_code=status.HTTP_201_CREATED)
async def setup(request: Request):
    """Endpoint to setup states.

    Use localstack to store payload.
    """
    payload = await request.json()
    items["states"] = payload
    return items["states"]