HTTP Client Effect — Aquilia Documentation
Comprehensive guide and documentation for HTTP Client Effect in the Aquilia framework. View API reference, examples, and implementation patterns.
EFFECTS / OUTBOUND HTTP HTTP Client Effect The HTTPEffect provides pre-configured, request-scoped outbound HTTP clients. Backed by the HTTPProvider and Aquilia's native HTTP client, it optimizes connection reuse, manages request timeouts, and handles connection pooling. Unified HTTP Connections Spawning arbitrary HTTP sessions (e.g. using standard library clients or raw requests libraries) per request degrades server throughput and risks socket exhaustion. The HTTPEffect integrates outbound queries into the ASGI lifecycle. Outbound connections share pooled HTTP sessions, enforce unified timeouts, and simplify key management. HTTPHandle API The acquired handle is an instance of HTTPHandle , which automatically parses JSON responses: await handle.get(url: str, **kwargs) -> Any Performs an async HTTP GET request. The URL path is appended to the provider's base URL. Returns decoded JSON. await handle.post(url: str, *, json: Any = None, **kwargs) -> Any Performs an async HTTP POST request, forwarding the json payload. Returns decoded JSON. await handle.put(url: str, *, json: Any = None, **kwargs) -> Any Performs an async HTTP PUT request, forwarding the json payload. Returns decoded JSON. await handle.delete(url: str, **kwargs) -> Any Performs an async HTTP DELETE request. Returns decoded JSON. Usage: Stripe Billing Sync The example below demonstrates querying the Stripe Billing API to check subscription details and issue invoice charge triggers: from aquilia.controller import Controller, POST, RequestCtx from aquilia.flow import requires from aquilia.effects import HTTPEffect, DBTx class StripeBillingController(Controller): # Require HTTP client capability and database access effects = [ HTTPEffect(service="stripe"), DBTx["write"] ] @POST("/billing/sync-subscription") async def sync_stripe_subscription(self, ctx: RequestCtx) -> dict: http = ctx.get_effect("HTTP") # HTTPHandle instance db = ctx.get_effect("DBTx") # DBTxHandle instance body = await ctx.json() # 1. Fetch live subscription stats from Stripe API stripe_sub = await http.get( f"/v1/subscriptions/ ", headers= "} ) # 2. Check if subscription is unpaid if stripe_sub.get("status") == "unpaid": # 3. Trigger immediate payment charge retries via POST API charge_response = await http.post( f"/v1/invoices/ /pay", headers= "} ) # Update local DB account status to flagged await db.execute( "UPDATE billing_accounts SET status = ? WHERE stripe_customer_id = ?", ("FLAGGED", stripe_sub["customer"]) ) return ctx.json( ) return ctx.json( ) Queue Effect Storage Effect )
Go to Homepage