#macro #generate #sdk #land #http #handler #procedural

macro land-sdk-macro

Land SDK macro provides a procedural macro to generate Land SDK code

8 releases

0.1.4 Oct 17, 2023
0.1.1 Sep 1, 2023
0.1.0 Aug 29, 2023
0.0.4 Jun 22, 2023

#2 in #land

33 downloads per month
Used in land-sdk

Apache-2.0

30KB
475 lines

land-sdk-macro

This crate provides the land_sdk(https://crates.io/crates/land-sdk) macro, which is used to generate the http handler function code. Do not use this crate directly.

Read more about the land-sdk crate here.


lib.rs:

Rust SDK Macro for Runtime.land.

This macro is used to develop Runtime.land functions in land-sdk. It should not be used directly.

Hello World

use land_sdk::http::{Body, Request, Response};
use land_sdk::http_main;

#[http_main]
pub fn handle_request(req: Request) -> Response {
    // read uri and method from request
    let url = req.uri().clone();
    let method = req.method().to_string().to_uppercase();

    // build response
    http::Response::builder()
        .status(200)
        .header("X-Request-Url", url.to_string())
        .header("X-Request-Method", method)
        .body(Body::from("Hello Runtime.land!!"))
        .unwrap()
}

Dependencies

~1–1.5MB
~31K SLoC