Attribute Macro response_status_code

Source
#[response_status_code]
Expand description

Sets the HTTP status code for the response.

This attribute macro configures the HTTP status code that will be sent with the response. The status code can be provided as a numeric literal or a global constant.

ยงUsage

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

const CUSTOM_STATUS: i32 = 418;

#[response_status_code(200)]
async fn success_handler(ctx: Context) {
    // Response will have status code 200
}

#[response_status_code(404)]
async fn not_found_handler(ctx: Context) {
    // Response will have status code 404
}

#[response_status_code(CUSTOM_STATUS)]
async fn custom_handler(ctx: Context) {
    // Response will have status code from global constant
}

The macro accepts a numeric HTTP status code (e.g., 200, 404, 500) or a global constant and should be applied to async functions that accept a Context parameter.