Last active
March 17, 2018 16:28
-
-
Save sean3z/1c9f00f19556272123de05053ccd3058 to your computer and use it in GitHub Desktop.
Adding our Hero endpoints
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
#![feature(plugin)] | |
#![plugin(rocket_codegen)] | |
extern crate rocket; | |
#[macro_use] extern crate rocket_contrib; | |
#[macro_use] extern crate serde_derive; | |
use rocket_contrib::{Json, Value}; | |
mod hero; | |
use hero::{Hero}; | |
#[post("/", data = "<hero>")] | |
fn create(hero: Json<Hero>) -> Json<Hero> { | |
hero | |
} | |
#[get("/")] | |
fn read() -> Json<Value> { | |
Json(json!([ | |
"hero 1", | |
"hero 2" | |
])) | |
} | |
#[put("/<id>", data = "<hero>")] | |
fn update(id: i32, hero: Json<Hero>) -> Json<Hero> { | |
hero | |
} | |
#[delete("/<id>")] | |
fn delete(id: i32) -> Json<Value> { | |
Json(json!({"status": "ok"})) | |
} | |
fn main() { | |
rocket::ignite() | |
.mount("/hero", routes![create, update, delete]) | |
.mount("/heroes", routes![read]) | |
.launch(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment