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 = "Dynamic content from constant";

#[response_body("Hello, World!")]
async fn hello_handler(ctx: Context) {
    // Response will have body "Hello, World!"
}

#[response_body("{\"message\": \"success\"}")]
async fn json_response_handler(ctx: Context) {
    // Response will have JSON body
}

#[response_body(RESPONSE_DATA)]
async fn dynamic_body_handler(ctx: Context) {
    // Response will have body from global constant
}

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.