Use the HTTP client in your application
The same IHttpManager is available to HTTP, Reactor and queue workers. A type annotation on a controller action, command or job tells Orionis which service to pass in. The Http facade in the first request uses that same service. The examples below share one function so they agree on what a missing product means.
If a booted application needs the manager object itself, use await Http.resolve() after from orionis.support.facades import Http. It returns the same instance as await app.make(IHttpManager). Inside an injected handler you already have that object as http.
Put the provider contract in one place
Section titled “Put the provider contract in one place”Start with the catalog profile from configuration. Create app/services/catalog.py and make app/services an importable package (an empty __init__.py is enough). In this example the provider returns 200 with {"data":{"name":"Desk lamp"}} or 404 when a product is missing.
from orionis.http.client.contracts import IHttpManager
class CatalogContractError(ValueError): pass
async def product_name(http: IHttpManager, product_id: int) -> str | None: result = await http.client("catalog").acceptJson().get(f"/products/{product_id}") if result.status() == 404: return None result.throw() if not result.ok(): raise CatalogContractError("Expected 200 from the catalog") name = result.json("data.name", default=None) if not isinstance(name, str): raise CatalogContractError("Expected a product name") return nameHere 404 has a business meaning. Other 4xx/5xx statuses raise an exception. A redirect, an unexpected success status or a document with the wrong shape is a contract error. Keeping these decisions in the service prevents every caller from interpreting the provider differently.
Serve a product through a controller
Section titled “Serve a product through a controller”Save this as app/http/controllers/catalog_controller.py. The framework supplies the integer from the incoming URL and injects IHttpManager. The outgoing result belongs to the catalog. Construct a separate JSON response for your caller and expose only the fields your own API promises.
from app.services.catalog import CatalogContractError, product_namefrom orionis.http import JSONResponse, responsefrom orionis.http.base import BaseControllerfrom orionis.http.client.contracts import IHttpManagerfrom orionis.http.client.exceptions import ( HttpCapacityException, HttpDecodeException, HttpSizeLimitException, HttpStatusException, HttpTimeoutException, HttpTransportException,)
class CatalogController(BaseController): async def show(self, product_id: int, http: IHttpManager) -> JSONResponse: try: name = await product_name(http, product_id) except HttpTimeoutException: return response.json({"error": "catalog_timeout"}, status_code=504) except HttpCapacityException: return response.json({"error": "catalog_busy"}, status_code=503) except ( CatalogContractError, HttpDecodeException, HttpSizeLimitException, HttpStatusException, HttpTransportException, ): return response.json({"error": "catalog_unavailable"}, status_code=502) if name is None: return response.json({"error": "product_not_found"}, status_code=404) return response.json({"id": product_id, "name": name})Add this declaration to the route file registered as api in bootstrap/app.py, usually routes/api.py. Place it outside existing route groups for this exact URL.
from app.http.controllers.catalog_controller import CatalogControllerfrom orionis.support.facades import Route
Route.get("/catalog/{product_id:int}", [CatalogController, "show"])With a real, configured provider, start uv run python -B reactor serve and open /catalog/42 on the displayed address. A match returns {"id":42,"name":"Desk lamp"} for the sample payload. The 502, 503 and 504 mappings above are choices made by this controller. HTTP controllers
Run a check from the terminal
Section titled “Run a check from the terminal”Save app/console/commands/catalog_check_command.py. Reactor discovers the command class and supplies its typed dependency to handle().
from app.services.catalog import product_namefrom orionis.console.base import BaseCommandfrom orionis.http.client.contracts import IHttpManager
class CatalogCheckCommand(BaseCommand): signature = "catalog:check" description = "Check that the catalog can return product 42."
async def handle(self, http: IHttpManager) -> int: name = await product_name(http, 42) if name is None: self.error("Product 42 was not found.") return 1 self.info(name) return 0uv run python -B reactor catalog:checkWith a real provider, a successful lookup prints the product name and exits with code 0. A missing product prints the message and exits with code 1. Transport and provider failures propagate to the command handler. A fresh Reactor process owns startup and shutdown. Create a command
Call the API in a queue worker
Section titled “Call the API in a queue worker”Save app/jobs/save_product_name_job.py. Only the product ID belongs in the queued message. The worker loads its own configuration and resolves the HTTP and storage services when it executes the job.
from app.services.catalog import product_namefrom orionis.http.client.contracts import IHttpManagerfrom orionis.queues import BaseJobfrom orionis.storage.contracts.manager import IStorageManager
class SaveProductNameJob(BaseJob): __slots__ = ("product_id",) product_id: int
def __init__(self, product_id: int) -> None: self.product_id = product_id
async def handle(self, http: IHttpManager, storage: IStorageManager) -> None: name = await product_name(http, self.product_id) if name is not None: await storage.disk("local").put(f"catalog/{self.product_id}.txt", name)Submit the job from a booted async command or controller. Orionis returns a job ID. The worker writes the name to catalog/42.txt on the local disk when product 42 exists.
from app.jobs.save_product_name_job import SaveProductNameJobfrom orionis.support.facades import Queue
async def queue_product(product_id: int) -> str: return await Queue.dispatch(SaveProductNameJob(product_id))With the sync queue connection, the work executes during dispatch. With a configured database queue, run its migrations and worker as described in jobs and dispatch. This job reads the provider and overwrites a known file. If you replace that operation with a remote write, account for worker retries and duplicate deliveries. Writes and retries
Own the lifecycle in a standalone script
Section titled “Own the lifecycle in a standalone script”Save check_catalog.py in the project root. A standalone Python process calls boot() before resolving services and aclose() when it finishes. Both calls run on the same event loop. HTTP handlers, commands and jobs already run under a framework owner.
import asyncio
from app.services.catalog import product_namefrom bootstrap.app import appfrom orionis.http.client.contracts import IHttpManager
async def main() -> None: await app.boot() try: http = await app.make(IHttpManager) print(await product_name(http, 42)) finally: await app.aclose()
if __name__ == "__main__": asyncio.run(main())uv run python check_catalog.pyThe script prints the name, or None for a missing product. For repeatable local checks keep the placeholder domain and use fake responses. For a live check choose your provider’s real origin. Connection ownership and shutdown