mirror of
https://github.com/guilhermewerner/rust-api
synced 2025-06-15 14:35:15 +00:00
Create Sample Rocket Json API
This commit is contained in:
2
.cargo/config.toml
Normal file
2
.cargo/config.toml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
[build]
|
||||||
|
target-dir = "Binaries"
|
20
Cargo.toml
Normal file
20
Cargo.toml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
[package]
|
||||||
|
name = "API"
|
||||||
|
version = "0.0.1"
|
||||||
|
description = "Rust API"
|
||||||
|
repository = "https://github.com/GuilhermeWerner/RustAPI"
|
||||||
|
authors = ["GuilhermeWerner <guilhermeqwerner@gmail.com>"]
|
||||||
|
license = "MIT"
|
||||||
|
edition = "2018"
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name="Server"
|
||||||
|
path = "Source/Server.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
rocket = "0.4.6"
|
||||||
|
rocket_contrib = "0.4.6"
|
||||||
|
# serde = "1.0"
|
||||||
|
# serde_json = "1.0"
|
||||||
|
# serde_derive = "1.0"
|
31
Source/Server.rs
Normal file
31
Source/Server.rs
Normal 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();
|
||||||
|
}
|
1
rust-toolchain
Normal file
1
rust-toolchain
Normal file
@ -0,0 +1 @@
|
|||||||
|
nightly
|
Reference in New Issue
Block a user