Add canapi and try to use for the API
This commit is contained in:
@@ -0,0 +1 @@
|
||||
pub mod posts;
|
||||
@@ -0,0 +1,11 @@
|
||||
use rocket_contrib::Json;
|
||||
use serde_json;
|
||||
|
||||
use plume_models::db_conn::DbConn;
|
||||
use plume_models::posts::Post;
|
||||
|
||||
#[get("/posts/<id>")]
|
||||
fn get(id: i32, conn: DbConn) -> Json<serde_json::Value> {
|
||||
let post = Post::get(&*conn, id).unwrap();
|
||||
Json(post.to_json(&*conn))
|
||||
}
|
||||
@@ -36,6 +36,7 @@ use rocket_contrib::Template;
|
||||
use rocket_csrf::CsrfFairingBuilder;
|
||||
use workerpool::{Pool, thunk::ThunkWorker};
|
||||
|
||||
mod api;
|
||||
mod inbox;
|
||||
mod setup;
|
||||
mod routes;
|
||||
@@ -142,6 +143,9 @@ fn main() {
|
||||
|
||||
routes::errors::csrf_violation
|
||||
])
|
||||
.mount("/api/v1", routes![
|
||||
api::posts::get
|
||||
])
|
||||
.catch(catchers![
|
||||
routes::errors::not_found,
|
||||
routes::errors::server_error
|
||||
|
||||
Reference in New Issue
Block a user