HTTP (outbound)
forze[http] is the outbound HTTP transport — an httpx-backed client behind the
HttpServicePort. You describe an external API as a service of typed operations
and call it from handlers through the context, never touching httpx directly.
Install¶
uv add 'forze[http]'
The client¶
from forze_http import HttpClient
http = HttpClient()
RoutedHttpClient resolves per-tenant base URLs and credentials from secrets.
Wire it¶
Register a service config per HttpServiceSpec.name:
from forze.application.execution import DepsRegistry, LifecyclePlan
from forze_http import HttpAuthConfig, HttpClient, HttpDepsModule, HttpServiceConfig, http_lifecycle_step
payments = HttpServiceConfig(
base_url="https://api.payments.example.com",
auth=HttpAuthConfig(kind="bearer", token="…"),
)
deps = DepsRegistry.from_modules(HttpDepsModule(client=HttpClient(), services={"payments": payments}))
lifecycle = LifecyclePlan.from_steps(http_lifecycle_step())
The service's operations are declared with async_http_op on a
BaseHttpIntegration subclass (from forze.application.integrations.http) and
resolved via ctx.http.service(spec).
What it provides¶
| Contract | Keyed by |
|---|---|
| Outbound HTTP service (typed operations) | HttpServiceSpec.name (services) |
Notes¶
- A service is either static (
base_url) or per-tenant —tenant_aware=Trueforbids a staticbase_url(it comes from secrets) and requiressecret_ref_for_tenant. HttpAuthConfigcoversbearer,api_key, and custom-headerauth.- When the caller has a deadline bound, the adapter
forwards the remaining budget as an
X-Forze-Deadline-Budgetheader so a downstream Forze service can inherit it; opt out per service withHttpServiceConfig(propagate_deadline=False). - The
HttpServiceSpec/HttpOperationSpec/HttpServicePortcontracts live in core;forze_httpprovides the httpx transport and wiring.