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
Delete
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
Get
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
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
Patch
Post
Put
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