2017-04-17 02:48:59 +00:00
|
|
|
|
###############################################################################
|
|
|
|
|
# Top features: displayed in the header under the introductory text.
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
|
[release]
|
|
|
|
|
url = "https://crates.io/crates/rocket"
|
2017-05-27 03:38:56 +00:00
|
|
|
|
version = "0.2.7"
|
|
|
|
|
date = "May 26, 2017"
|
2017-04-17 02:48:59 +00:00
|
|
|
|
|
|
|
|
|
[[top_features]]
|
|
|
|
|
title = "Type Safe"
|
|
|
|
|
text = "From request to response Rocket ensures that your types mean something."
|
|
|
|
|
image = "helmet"
|
|
|
|
|
button = "Learn More"
|
|
|
|
|
url = "/overview/#how-rocket-works"
|
|
|
|
|
|
|
|
|
|
[[top_features]]
|
|
|
|
|
title = "Boilerplate Free"
|
|
|
|
|
text = "Spend your time writing code that really matters, and let Rocket generate the rest."
|
|
|
|
|
image = "robot-free"
|
|
|
|
|
button = "See Examples"
|
|
|
|
|
url = "/overview/#anatomy-of-a-rocket-application"
|
|
|
|
|
|
|
|
|
|
[[top_features]]
|
|
|
|
|
title = "Easy To Use"
|
|
|
|
|
text = "Rocket makes extensive use of Rust's code generation tools to provide a clean API."
|
|
|
|
|
image = "sun"
|
|
|
|
|
button = "Get Started"
|
|
|
|
|
url = "/guide"
|
|
|
|
|
margin = 2
|
|
|
|
|
|
|
|
|
|
[[top_features]]
|
|
|
|
|
title = "Extensible"
|
|
|
|
|
text = "Easily create your own primitives that any Rocket application can use."
|
|
|
|
|
image = "telescope"
|
|
|
|
|
button = "See How"
|
|
|
|
|
url = "/overview/#anatomy-of-a-rocket-application"
|
|
|
|
|
margin = 9
|
|
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
# Sections: make sure there are an odd number so colors work out.
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
|
[[sections]]
|
|
|
|
|
title = "Hello, Rocket!"
|
|
|
|
|
code = '''
|
|
|
|
|
#![feature(plugin)]
|
|
|
|
|
#![plugin(rocket_codegen)]
|
|
|
|
|
|
|
|
|
|
extern crate rocket;
|
|
|
|
|
|
|
|
|
|
#[get("/hello/<name>/<age>")]
|
|
|
|
|
fn hello(name: &str, age: u8) -> String {
|
|
|
|
|
format!("Hello, {} year old named {}!", age, name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
rocket::ignite().mount("/", routes![hello]).launch();
|
|
|
|
|
}
|
|
|
|
|
'''
|
|
|
|
|
text = '''
|
|
|
|
|
This is a **complete Rocket application**. It does exactly what you would
|
|
|
|
|
expect. If you were to visit **http://localhost:8000/hello/John/58**, you’d
|
|
|
|
|
see:
|
|
|
|
|
|
|
|
|
|
<span class="callout">Hello, 58 year old named John!</span>
|
|
|
|
|
|
|
|
|
|
If someone visits a path with an `<age>` that isn’t a `u8`, Rocket doesn’t
|
|
|
|
|
blindly call `hello`. Instead, it tries other matching routes or returns a
|
|
|
|
|
**404**.
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
[[sections]]
|
|
|
|
|
title = "Forms? Check!"
|
|
|
|
|
code = '''
|
|
|
|
|
#[derive(FromForm)]
|
|
|
|
|
struct Task {
|
|
|
|
|
description: String,
|
|
|
|
|
completed: bool
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[post("/", data = "<task>")]
|
|
|
|
|
fn new(task: Form<Task>) -> Flash<Redirect> {
|
|
|
|
|
if task.get().description.is_empty() {
|
|
|
|
|
Flash::error(Redirect::to("/"), "Cannot be empty.")
|
|
|
|
|
} else {
|
|
|
|
|
Flash::success(Redirect::to("/"), "Task added.")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
'''
|
|
|
|
|
text = '''
|
|
|
|
|
Handling forms **is simple and easy**. Simply derive `FromForm` for your
|
|
|
|
|
structure and let Rocket know which parameter to use. Rocket **parses and
|
|
|
|
|
validates** the form request, creates the structure, and calls your function.
|
|
|
|
|
|
|
|
|
|
Bad form request? Rocket doesn’t call your function! What if you want to know
|
|
|
|
|
if the form was bad? Simple! Change the type of `task` to `Option` or
|
|
|
|
|
`Result`!
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
[[sections]]
|
|
|
|
|
title = "JSON, out of the box."
|
|
|
|
|
code = '''
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
struct Message {
|
|
|
|
|
contents: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[put("/<id>", data = "<message>")]
|
|
|
|
|
fn update(id: ID, message: JSON<Message>) -> JSON<Value> {
|
|
|
|
|
if DB.contains_key(&id) {
|
|
|
|
|
DB.insert(id, &message.contents);
|
|
|
|
|
JSON(json!{ "status": "ok" })
|
|
|
|
|
} else {
|
|
|
|
|
JSON(json!{ "status": "error" })
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
'''
|
|
|
|
|
text = '''
|
|
|
|
|
Rocket has first-class support for JSON, right out of the box. Simply derive
|
|
|
|
|
`Deserialize` or `Serialize` to receive or return JSON, respectively.
|
|
|
|
|
|
|
|
|
|
Like other important features, JSON works through Rocket’s `FromData` trait,
|
|
|
|
|
Rocket’s approach to deriving types from body data. It works like this:
|
|
|
|
|
specify a `data` route parameter of any type that implements `FromData`. A
|
|
|
|
|
value of that type will then be created automatically from the incoming
|
|
|
|
|
request body. Best of all, you can implement `FromData` for your types!
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
# Buttom features: displayed above the footer.
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
|
[[bottom_features]]
|
|
|
|
|
title = 'Templating'
|
|
|
|
|
text = "Rocket makes rendering templates a breeze with built-in templating support."
|
|
|
|
|
image = 'templating-icon'
|
|
|
|
|
url = '/guide/responses/#templates'
|
|
|
|
|
button = 'Learn More'
|
|
|
|
|
color = 'blue'
|
|
|
|
|
|
|
|
|
|
[[bottom_features]]
|
|
|
|
|
title = 'Cookies'
|
|
|
|
|
text = "Cookies are first-class in Rocket. View, add, or remove cookies without hassle."
|
|
|
|
|
image = 'cookies-icon'
|
|
|
|
|
url = '/guide/requests/#request-guards'
|
|
|
|
|
button = 'Learn More'
|
|
|
|
|
color = 'purple'
|
|
|
|
|
margin = -6
|
|
|
|
|
|
|
|
|
|
[[bottom_features]]
|
|
|
|
|
title = 'Streams'
|
|
|
|
|
text = "Rocket streams all incoming and outgoing data, so size isn't a concern."
|
|
|
|
|
image = 'streams-icon'
|
|
|
|
|
url = '/guide/requests/#streaming'
|
|
|
|
|
button = 'Learn More'
|
|
|
|
|
color = 'red'
|
|
|
|
|
margin = -29
|
|
|
|
|
|
|
|
|
|
[[bottom_features]]
|
|
|
|
|
title = 'Config Environments'
|
|
|
|
|
text = "Configure your application your way for development, staging, and production."
|
|
|
|
|
image = 'config-icon'
|
|
|
|
|
url = '/guide/overview/#configuration'
|
|
|
|
|
button = 'Learn More'
|
|
|
|
|
color = 'yellow'
|
|
|
|
|
margin = -3
|
|
|
|
|
|
|
|
|
|
[[bottom_features]]
|
|
|
|
|
title = 'Query Params'
|
|
|
|
|
text = "Handling query parameters isn’t an afterthought in Rocket."
|
|
|
|
|
image = 'query-icon'
|
|
|
|
|
url = '/guide/requests/#query-strings'
|
|
|
|
|
button = 'Learn More'
|
|
|
|
|
color = 'orange'
|
|
|
|
|
margin = -3
|
|
|
|
|
|
|
|
|
|
[[bottom_features]]
|
|
|
|
|
title = 'Testing Library'
|
|
|
|
|
text = "Unit test your applications with ease using the built-in testing library."
|
|
|
|
|
image = 'testing-icon'
|
|
|
|
|
url = '/guide/testing#testing'
|
|
|
|
|
button = 'Learn More'
|
|
|
|
|
color = 'green'
|
|
|
|
|
|
|
|
|
|
# Blocked on Hyper/OpenSSL.
|
|
|
|
|
# [[bottom_features]]
|
|
|
|
|
# title = 'Signed Sessions'
|
|
|
|
|
# text = "Safe, secure, signed sessions are built-in to Rocket so your users can stay safe."
|
|
|
|
|
# image = 'sessions-icon'
|
|
|
|
|
# url = '/overview'
|
|
|
|
|
# button = 'Learn More'
|
|
|
|
|
# color = 'green'
|