#[request_body_json]
Expand description
Parses the request body as JSON into a specified variable and type.
This attribute macro extracts and deserializes the request body content as JSON into a variable with the specified type. The body content is parsed as JSON using serde.
ยงUsage
use hyperlane::*;
use hyperlane_macros::*;
use serde::Deserialize;
#[derive(Deserialize, Clone)]
struct UserData {
name: String,
age: u32,
}
#[request_body_json(user_data: UserData)]
async fn handle_user(ctx: Context) {
if let Ok(data) = user_data {
// Use the parsed user data
}
}
The macro accepts a variable name and type in the format variable_name: Type
.
The variable will be available in the function scope as a Result<Type, JsonError>
.