Create Sample Rocket Json API

This commit is contained in:
GuilhermeWerner
2021-01-18 20:08:39 -03:00
parent ae20f2085e
commit b8440043ab
4 changed files with 54 additions and 0 deletions

31
Source/Server.rs Normal file
View File

@ -0,0 +1,31 @@
#![feature(proc_macro_hygiene, decl_macro)]
#[macro_use]
extern crate rocket;
#[macro_use]
extern crate rocket_contrib;
use rocket_contrib::json::{Json, JsonValue};
#[get("/")]
fn hello() -> JsonValue {
return json!({ "TribuFu": "Hello World" });
}
#[catch(404)]
fn not_found() -> JsonValue {
return json!({
"Error": "RESOURCE_NOT_FOUND"
});
}
fn rocket() -> rocket::Rocket {
return rocket::ignite()
.mount("/", routes![hello])
.register(catchers![not_found]);
}
fn main() {
rocket().launch();
}