Macro post

Source
macro_rules! post {
    ($post_handler: ident) => { ... };
    ($post_handler: ident, $request: ident, $response: ident) => { ... };
}
Expand description

Create a handler that accepts a post payload and returns a response.

You can use raw bytes, or json-marshalled types.

Raw:

momento_functions::post!(ping);
fn ping(payload: Vec<u8>) -> FunctionResult<Vec<u8>> {
    Ok(b"pong".to_vec())
}

Typed JSON:

#[derive(serde::Deserialize)]
struct Request {
    name: String,
}
#[derive(serde::Serialize)]
struct Response {
    message: String,
}

momento_functions::post!(greet, Request, Response);
fn greet(request: Request) -> FunctionResult<Response> {
    Ok(Response { message: format!("Hello, {}!", request.name) })
}