Skip to content

Instantly share code, notes, and snippets.

@NoraCodes
Created January 3, 2017 17:41
Show Gist options
  • Save NoraCodes/ff2d36a59f2d2a8c1ef2b8bdc58be4ca to your computer and use it in GitHub Desktop.
Save NoraCodes/ff2d36a59f2d2a8c1ef2b8bdc58be4ca to your computer and use it in GitHub Desktop.
A simple greeter app with Rocket
[package]
name = "rocket_test"
version = "0.1.0"
authors = ["SilverWingedSeraph <[email protected]>"]
[dependencies]
rocket = "0.1.3"
rocket_codegen = "0.1.3"
#![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