response_body

Attribute Macro response_body 

Source
#[response_body]
Expand description

Sets the HTTP response body.

This attribute macro configures the HTTP response body that will be sent with the response. The body content can be provided as a string literal or a global constant.

ยงUsage

use hyperlane::*;
use hyperlane_macros::*;

const RESPONSE_DATA: &str = "{\"status\": \"success\"}";

#[route("/response_body")]
struct ResponseBody;

impl ServerHook for ResponseBody {
    async fn new(_ctx: &Context) -> Self {
        Self
    }

    #[response_body(&RESPONSE_DATA)]
    async fn handle(self, ctx: &Context) {}
}

impl ResponseBody {
    #[response_body(&RESPONSE_DATA)]
    async fn response_body_with_ref_self(&self, ctx: &Context) {}
}

#[response_body("standalone response body")]
async fn standalone_response_body_handler(ctx: &Context) {}

The macro accepts a string literal or global constant for the response body and should be applied to async functions that accept a &Context parameter.