Skip to content
This repository was archived by the owner on Oct 29, 2021. It is now read-only.
/ obsidian Public archive

Ergonomic async http framework for reliable and efficient web

License

Notifications You must be signed in to change notification settings

obsidian-rs/obsidian

Repository files navigation

Obsidian Logo

Obsidian

Obsidian is an ergonomic Rust async http framework for reliable and efficient web.

Obsidian serve

Get Started

[dependencies]
# add these 2 dependencies in Cargo.toml file
obsidian = "0.2.2"
tokio = "0.2.21"

Hello World

use obsidian::{context::Context, App};

#[tokio::main]
async fn main() {
    let mut app: App = App::new();
    app.get("/", |ctx: Context| async { ctx.build("Hello World").ok() });
    app.listen(3000).await;
}

Hello World (with handler function)

use obsidian::{context::Context, handler::ContextResult, App};

async fn hello_world(ctx: Context) -> ContextResult {
    ctx.build("Hello World").ok()
}

#[tokio::main]
async fn main() {
    let mut app: App = App::new();
    app.get("/", hello_world);
    app.listen(3000).await;
}

JSON Response

use obsidian::{context::Context, handler::ContextResult, App};
use serde::*;

async fn get_user(ctx: Context) -> ContextResult {
    #[derive(Serialize, Deserialize)]
    struct User {
        name: String,
    };

    let user = User {
        name: String::from("Obsidian"),
    };
    ctx.build_json(user).ok()
}

#[tokio::main]
async fn main() {
    let mut app: App = App::new();
    app.get("/user", get_user);
    app.listen(3000).await;
}

More Examples

Examples are located in example folder. You can run these examples by using:

cargo run --example [name]

// show a list of available examples
cargo run --example 

// run the example
cargo run --example example

App Lifecycle

app lifecycle

Contributors

Current State

Under active development and NOT READY FOR PRODUCTION YET!