Fullstack Rust by Nate Murray

Fullstack Rust by Nate Murray

Author:Nate Murray [Nate Murray]
Language: eng
Format: epub, pdf
Publisher: leanpub.com
Published: 2020-02-18T00:00:00+00:00


Publishing a post

The process of publishing a post in our API is quite simple, we just need a post_id in the path and can then rely on the model code we wrote earlier:

src/routes/posts.rs 42 fn publish_post( 43 post_id: web::Path<i32>, 44 pool: web::Data<Pool>, 45 ) -> impl Future<Item = HttpResponse, Error = AppError> { 46 web::block(move || { 47 let conn: &SqliteConnection = &pool.get().unwrap(); 48 models::publish_post(conn, post_id.into_inner()) 49 }) 50 .then(convert) 51 }

Fetching posts

We can fetch posts either given a user_id or just fetch them all. In the first case we expect to find the id in the path:

src/routes/posts.rs 53 fn user_posts( 54 user_id: web::Path<i32>, 55 pool: web::Data<Pool>, 56 ) -> impl Future<Item = HttpResponse, Error = AppError> { 57 web::block(move || { 58 let conn: &SqliteConnection = &pool.get().unwrap(); 59 models::user_posts(conn, user_id.into_inner()) 60 }) 61 .then(convert) 62 }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.