5 releases
0.2.2 | May 3, 2020 |
---|---|
0.2.1 | Apr 26, 2020 |
0.1.0 |
|
0.1.0-alpha.1 | Dec 31, 2019 |
#32 in #http-framework
35 downloads per month
105KB
2.5K
SLoC
Obsidian
Obsidian is an ergonomic Rust async http framework for reliable and efficient web.
Hello World
use obsidian::{context::Context, App};
#[tokio::main]
async fn main() {
let mut app: App = App::new();
let addr = ([127, 0, 0, 1], 3000).into();
app.get("/", |ctx: Context| async { ctx.build("Hello World").ok() });
app.listen(&addr, || {
println!("server is listening to {}", &addr);
}).await;
}
Hello World (with handler function)
use obsidian::{context::Context, App, ContextResult};
async fn hello_world(ctx: Context) -> ContextResult {
ctx.build("Hello World").ok()
}
#[tokio::main]
async fn main() {
let mut app: App = App::new();
let addr = ([127, 0, 0, 1], 3000).into();
app.get("/", hello_world);
app.listen(&addr, || {
println!("server is listening to {}", &addr);
})
.await;
}
JSON Response
use obsidian::{context::Context, App, ContextResult};
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();
let addr = ([127, 0, 0, 1], 3000).into();
app.get("/user", get_user);
app.listen(&addr, || {
println!("server is listening to {}", &addr);
})
.await;
}
Example Files
Example are located in example/main.rs
.
Run Example
cargo run --example example
Current State
NOT READY FOR PRODUCTION YET!
Dependencies
~14–27MB
~384K SLoC