Created
January 3, 2017 17:41
-
-
Save NoraCodes/ff2d36a59f2d2a8c1ef2b8bdc58be4ca to your computer and use it in GitHub Desktop.
A simple greeter app with Rocket
This file contains hidden or 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
[package] | |
name = "rocket_test" | |
version = "0.1.0" | |
authors = ["SilverWingedSeraph <[email protected]>"] | |
[dependencies] | |
rocket = "0.1.3" | |
rocket_codegen = "0.1.3" |
This file contains hidden or 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)] | |
#![feature(custom_derive)] | |
#![plugin(rocket_codegen)] | |
extern crate rocket; | |
use rocket::request::Form; | |
use rocket::response::content::HTML; | |
const FORM_TEMPLATE: &'static str = " | |
<html> | |
<head> | |
<title> Rocket Test </title> | |
</head> | |
<body> | |
<form action='name' method='POST'> | |
What is your name?<br /> | |
<input type='text' name='name'> | |
</form> | |
</body>"; | |
#[get("/")] | |
fn index() -> HTML<String> { | |
HTML(String::from(FORM_TEMPLATE)) | |
} | |
#[derive(FromForm)] | |
struct FormName { | |
name: String | |
} | |
#[post("/name", data="<name>")] | |
fn name(name: Form<FormName>) -> String { | |
let name_data = name.get(); | |
format!("Hello, {}", name_data.name) | |
} | |
fn main() { | |
rocket::ignite().mount("/", routes![index, name]).launch(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment