heres the code ``` #[derive(Deserialize, Serialize, Debug)] struct Thing { thing_id: String,

heres the code

#[derive(Deserialize, Serialize, Debug)]
struct Thing {
    thing_id: String,
    desc: String,
    num: u32,
}

#[event(fetch, respond_with_errors)]
async fn main(req: Request, env: Env, _ctx: Context) -> Result<Response> {
    Router::new()
        .get_async("/:id", |_, ctx| async move {
            let id = ctx.param("id").unwrap();
            let d1 = ctx.env.d1("DB")?;

            let statement = d1.prepare("SELECT * FROM todos WHERE id = ?");
            let query = statement.bind(&[id.into()])?;

            let result = query.first::<Thing>(None).await?;

            match result {
                Some(thing) => Response::from_json(&thing),
                None => Response::error("Not found", 404),
            }
        })
        .run(req, env)
        .await
}
Was this page helpful?