Skip to content

Instantly share code, notes, and snippets.

@sean3z
Last active March 17, 2018 16:28
Show Gist options
  • Save sean3z/1c9f00f19556272123de05053ccd3058 to your computer and use it in GitHub Desktop.
Save sean3z/1c9f00f19556272123de05053ccd3058 to your computer and use it in GitHub Desktop.
Adding our Hero endpoints
#![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