Skip to main content

cliffracer-http

HTTP routes and websockets for cliffracer services, on FastAPI.

Core serves GET /health and GET /info from an asyncio listener. This package is for services that also serve routes of their own.

from cliffracer import CliffracerService, rpc
from pydantic import BaseModel

from cliffracer_http import HttpExtension


class Order(BaseModel):
    sku: str
    qty: int


class OrderService(CliffracerService):
    http = HttpExtension()

    @rpc
    async def create(self, order: Order) -> str: ...

    @http.get("/orders/{order_id}")
    async def get_order(self, order_id: str) -> dict[str, str]: ...

The extension serves /health and /info on its own FastAPI app as well.

Ports

Declaring this extension gives the service one port: the extension's. It serves your routes, /health and /info, and the core listener does not bind.

HttpExtension listens on 8000. Set the port with HttpExtension(port=8080) or with CLIFFRACER_HTTP_PORT. CLIFFRACER_HTTP_HOST sets the bind address, which defaults to 0.0.0.0. ServiceConfig.health_port is what the core listener uses on a service that does not declare this extension.

Point probes at the extension's port.

Auto-Gateway for Dynamic RPC Ingress

AutoGatewayExtension dynamically mounts FastAPI HTTP endpoints backed by Cliffracer RPC services, automatically inferring HTTP verbs, parsing parameters, dispatching NATS RPC calls, translating error responses, and generating interactive OpenAPI docs.

Example Service Definition

from pydantic import BaseModel

from cliffracer import CliffracerService, rpc
from cliffracer_http import AutoGatewayExtension, HttpExtension


class UserModel(BaseModel):
    id: str
    name: str
    email: str


class CreateUserPayload(BaseModel):
    name: str
    email: str


class UserService(CliffracerService):
    name = "users"
    http = HttpExtension(port=8080)
    gateway = AutoGatewayExtension(prefix="/api/v1")

    @rpc
    async def get_user(self, user_id: str) -> UserModel:
        """Fetch user by id."""
        return UserModel(id=user_id, name="Alice", email="alice@example.com")

    @rpc
    async def create_user(self, payload: CreateUserPayload) -> UserModel:
        """Create new user."""
        return UserModel(id="usr_1", name=payload.name, email=payload.email)

    @rpc
    async def delete_user(self, user_id: str) -> bool:
        """Delete user by id."""
        return True

Verb and Route Mapping

Method name prefixes map to standard HTTP verbs:

  • get_user -> GET /api/v1/users/get_user?user_id=... (query parameters)
  • create_user -> POST /api/v1/users/create_user (JSON request body CreateUserPayload)
  • delete_user -> DELETE /api/v1/users/delete_user?user_id=... (query parameters)

The gateway prefixes routes with /{prefix}/{service_name}/{method_name} and infers:

  • GET: get_, list_, fetch_, find_, read_, search_, query_
  • POST: create_, add_, post_, insert_, register_, new_ (and default for unrecognized prefixes)
  • PUT: update_, set_, put_, modify_, replace_
  • PATCH: patch_
  • DELETE: delete_, remove_, drop_, clear_, cancel_

Dedicated Gateway

A dedicated gateway service can also front downstream services by passing service classes to targets:

from cliffracer import CliffracerService
from cliffracer_http import AutoGatewayExtension, HttpExtension


class GatewayService(CliffracerService):
    name = "gateway"
    http = HttpExtension(port=8080)
    gateway = AutoGatewayExtension(
        targets=[UserService],
        prefix="/api/v1",
    )

Swagger and OpenAPI Documentation

When running, FastAPI serves interactive documentation:

  • Swagger UI: http://localhost:8080/docs
  • OpenAPI JSON Schema: http://localhost:8080/openapi.json

Error Status Codes

  • 200 OK: Successful RPC response.
  • 422 Unprocessable Entity: Validation failure or downstream RPCError containing error details.
  • 502 Bad Gateway: Downstream RPC failure.
  • 504 Gateway Timeout: Downstream service timed out (RPCTimeoutError).
  • 500 Internal Server Error: Unhandled gateway exception.

Installed from PyPI, versioned in lockstep with cliffracer.

Metadata

Release files for cliffracer-http 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cliffracer-http 1.0.0
File Size Uploaded Provenance
cliffracer_http-1.0.0.tar.gz 24.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for cliffracer-http 1.0.0
File Interpreter ABI Platform
cliffracer_http-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 38.7 kB

Release files / cliffracer_http-1.0.0.tar.gz

Download URL cliffracer_http-1.0.0.tar.gz
Size 24.3 kB
Tags Source
SHA-256 checksum
How to use checksums
6e3e7a00f62dba51f057386fec356a928fee33be25a429f6caf6446cc3448c48
BLAKE2b-256 checksum
How to use checksums
3f4ab672639efc23a8e3956c06785d9db30c2527d46dc272e538e298b10ca4b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / cliffracer_http-1.0.0-py3-none-any.whl

Download URL cliffracer_http-1.0.0-py3-none-any.whl
Size 14.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a9f319fe27e70dc4ad94c6be0e045acd8d835de39f154dd15439bd6878d793f5
BLAKE2b-256 checksum
How to use checksums
42d8f730eb691ec9ad23cd6a62bd881d63c4b563de1fa6f690b80ad54a004ca5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for cliffracer-http 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page