January 2019
Intermediate to advanced
520 pages
14h 32m
English
The Rouille framework is very simple to use. It contains start_server functions that expect a function to handle every incoming request. Let's create a main function that uses a diesel crate with an r2d2 pool feature and calls a function to handle requests:
fn main() { env_logger::init(); let manager = ConnectionManager::<SqliteConnection>::new("test.db"); let pool = Pool::builder().build(manager).expect("Failed to create pool."); rouille::start_server("127.0.0.1:8001", move |request| { match handler(&request, &pool) { Ok(response) => { response }, Err(err) => { Response::text(err.to_string()) .with_status_code(500) } } }) }
We created a ConnectionManager for a local test.db SQLite database and a Pool instance with ...
Read now
Unlock full access