Last active
July 20, 2018 07:33
-
-
Save ubnt-intrepid/266ecd06d28b0072eb94d9c918183afd to your computer and use it in GitHub Desktop.
tsukuyomi 0.3 preview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[macro_use] | |
extern crate tsukuyomi; | |
extern crate http; | |
use tsukuyomi::App; | |
use http::Method; | |
fn establish_db_connection(addr: &str) -> Pool { ... } | |
fn main() -> tsukuyomi::AppResult<()> { | |
let pool = establish_db_connection("postgres://localhost/app"); | |
global_key!(static DB_POOL: Pool); | |
let app = App::builder() | |
.route(("/", hello)) | |
.mount(("/api", |scope| { | |
scope.route(("/posts", Method::GET, all_posts)) | |
.route(("/posts/:id", Method::GET, get_post)) | |
.route(("/posts", Method::POST, add_post)) | |
.route(("/posts/:id", Method::DELETE, delete_post)); | |
// scope-local value | |
scope.set(&DB_POOL, pool); | |
// scope-level error handler (implemented as a `Modifier`) | |
scope.modifier(JsonErrorHandler::new()); | |
}) | |
.finish()?; | |
tsukuyomi::run(app) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment