Skip to main content

http

Attribute Macro http 

Source
#[http]
Expand description

Lowers extension methods into named, composable HTTP programs.

This is the HTTP backend that alux_ext::ext(..., defunc(via = http)) selects. via = http resolves the name in the authoring scope, so a declaration imports it as use alux_http::http. Applying the attribute directly means the same thing.

Each method becomes a first-order HTTP program. A route handler written with op(...) is replaced by the operation type generated by alux_ext::ext(defunc), the declared input roles and output kind become bounds on the interpreter, and a call to another method of the same extension becomes a nested program.

use alux_ext::ext;
use alux_http::{HttpApiAlg, JsonOutAlg, http};

#[ext(name = StatusApiExt, defunc(via = http))]
impl<This> This
where
    This: HttpApiAlg + JsonOutAlg,
{
    /// Declares the status surface.
    fn status_api<Alg>(&self)
    where
        Alg: StatusAlg,
    {
        self.routes().get("/status", self.op(Alg::status_current).json())
    }
}

// The expansion also defines `StatusApiProgram<Alg>`.