obsidian-rs / obsidian

Ergonomic async http framework for reliable and efficient web
MIT License
26 stars 4 forks source link

Obsidian v0.3 Discussion #54

Open jk-gan opened 4 years ago

jk-gan commented 4 years ago

Version 0.3 is about Evolution, we hope to improve DX and productivity by converting it from a micro-framework into rails/phoenix like framework. And this is the first step:

pickfire commented 3 years ago

@jk-gan Just wondering, I tried following zero2prod for actix-web and I noticed that actix-web data extractor is not type-safe during compile time, it error out when I used the wrong data type at runtime. Looks like we have the same thing here, I am wondering if it would be good to explore that since we can probably guarantee that data during compile time?

jk-gan commented 3 years ago

can u provide some examples?

pickfire commented 3 years ago

The example that I have is in actix-web.

// cargo add actix-web actix-rt
use actix_web::{web, App, HttpServer, Responder};

async fn greet(_data: web::Data<String>) -> impl Responder {
    "Hello world"
}

#[actix_rt::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| App::new().route("/", web::get().to(greet)))
        .bind("127.0.0.1:8000")?
        .run()
        .await
}

It compiles perfectly fine, but

> curl 127.1:8000
App data is not configured, to configure use App::data()

I am sure obsidian have the same issue since it have Context which is checked at runtime. Not sure if it's possible to be able to check it during compile time.

So far, I never know any framework that solves this. If obsidian can successfully tackle this, I think it would be cool.