Skip to main content

Crate arcly_http_macros

Crate arcly_http_macros 

Source
Expand description

Procedural macros for arcly-http.

Six attribute macros — each emits a single, deterministic compile-time registration. No runtime registry mutation; collection happens at link time via inventory.

  • #[Injectable] on a struct → emits ProviderDescriptor + ctor
  • #[Module(providers(…), controllers(…), imports(…))] → emits ModuleDescriptor
  • #[Controller("/prefix", tags("t"))] on an impl block → walks inner items, consumes #[Get]/#[Post]/…/#[UseInterceptors] attributes on methods, emits one RouteDescriptor per method with the controller prefix already concatenated
  • #[Get/Post/Put/Delete/Patch("/path", …)] on a free fn → standalone route registration
  • #[UseInterceptors(A, B)] → wraps the handler thunk in the chain
  • #[circuit_breaker(threshold = N, cooldown = "Ns")] on an async fn wraps its body in a per-method static CircuitBreaker

Attribute Macros§

AuditLog
#[AuditLog(action = "…", resource = "…")] — emit one compliance audit record per invocation, keyed on the response status. Consumed by #[Controller]; pass-through marker on free fns.
CacheKey
#[CacheKey("template")] — custom key. Marker attribute; see CacheTTL.
CacheTTL
#[CacheTTL(N)] — TTL in seconds. Marker attribute consumed by the route macro and stuffed into RouteSpec.cache_ttl_secs. Pass-through here so the type system accepts it standalone.
Controller
#[Controller("/prefix", tags(..))] — declare an HTTP controller.
Delete
#[Delete("/path")] — map a method (or free function) to an HTTP DELETE route.
Deprecated
#[Deprecated(sunset = "YYYY-MM-DD")] on a #[Controller] impl — adds RFC 8594 Deprecation/Sunset headers to every response from this controller. Marker; consumed by #[Controller].
EncryptFields
#[EncryptFields(key = "tenant:acme", fields("ssn", "items.*.diagnosis"))] on a Serialize + Deserialize struct implements EncryptRecord: record.seal(&vault) returns a serde_json::Value with the declared fields sealed (safe for any durable sink); T::unseal(value, &vault) reverses it. Use seal_with_key/KeyId::subject(...) for per-subject keys minted at runtime (crypto-shredding granularity).
EventConsumer
#[EventConsumer] on an impl block — registers every #[EventPattern] method into the link-time event registry (the messaging analogue of #[Controller]). Methods take EventContext and return Result<(), String>.
EventPattern
#[EventPattern("topic")] — marks a method inside an #[EventConsumer] impl as the handler for one topic. Marker; consumed by #[EventConsumer].
Gateway
#[Gateway("/path")] — declare a WebSocket gateway.
Get
#[Get("/path")] — map a method (or free function) to an HTTP GET route.
Idempotent
#[Idempotent(ttl = "24h")] — Stripe-style Idempotency-Key handling: claim → run → store; retries replay the stored response; concurrent duplicates get 409. Consumed by #[Controller].
Injectable
#[Injectable] — turn a struct into a zero-lock DI provider.
MaskFields
#[MaskFields("email", "card:last4")] — redact these JSON response fields (plus the global Masker rules) before any durable layer sees the body. Consumed by #[Controller].
Module
#[Module(controllers(..), providers(..), imports(..))] — declare a unit of the application DAG.
Patch
#[Patch("/path")] — map a method (or free function) to an HTTP PATCH route.
Post
#[Post("/path")] — map a method (or free function) to an HTTP POST route.
Put
#[Put("/path")] — map a method (or free function) to an HTTP PUT route.
RequirePolicies
#[RequirePolicies("orders.refund", …)] — ABAC route gate: every listed action must Permit under the hot-reloadable PolicyEngine (default-deny). Consumed by #[Controller].
Subscribe
#[Subscribe("event::name")] — marker consumed by the enclosing #[Gateway] walker. Pass-through so it also type-checks if a tool resolves it directly.
Timeout
#[Timeout("2s")] — route deadline; 504 + future cancellation on expiry. Consumed by #[Controller]; pass-through marker on free fns.
Transactional
#[Transactional] — wrap the handler in a database transaction on the request-tenant’s pool: commit on Ok, rollback on Err/cancellation. Consumed by #[Controller]; pass-through marker on free fns.
UseInterceptors
#[UseInterceptors(A, B)] on a free fn — wraps that handler’s thunk.
Version
#[Version("v1")] on a #[Controller] impl — mounts every route under /v1/... and records the version in each RouteSpec. Marker; consumed by #[Controller].
circuit_breaker
#[circuit_breaker(..)] — wrap a method in a circuit breaker.