|
> That does seem a bit painful to me. It's because it's written using a low level library. Here's the first two sections (the http handling part) in Rocket: #![feature(plugin, custom_derive)]
#![plugin(rocket_codegen)]
extern crate rocket;
use rocket::request::Form;
#[derive(FromForm, Debug)]
struct NewMessage {
username: String,
message: String,
}
#[derive(FromForm, Debug)]
struct TimeRange {
before: Option<i64>,
after: Option<i64>,
}
#[post("/", data="<message>")]
fn message_create(message: Form<NewMessage>) -> String {
format!("{:?}", message)
}
#[get("/?<times>")]
fn message_query(times: TimeRange) -> String {
format!("{:?}", times)
}
fn main() {
rocket::ignite()
.mount("/", routes![message_create, message_query])
.launch();
}
|
A Python equivalent using the typing module: