mirror of https://github.com/rwf2/Rocket.git
Update docs for latest changes.
This commit is contained in:
parent
d4f9525b22
commit
f9e17ce7df
|
@ -131,7 +131,6 @@ program, which we reproduce below:
|
||||||
#![plugin(rocket_codegen)]
|
#![plugin(rocket_codegen)]
|
||||||
|
|
||||||
extern crate rocket;
|
extern crate rocket;
|
||||||
use rocket::Rocket;
|
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
fn hello() -> &'static str {
|
fn hello() -> &'static str {
|
||||||
|
@ -139,7 +138,7 @@ fn hello() -> &'static str {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
Rocket::mount_and_launch("/hello", routes![hello]);
|
rocket::ignite().mount("/hello", routes![hello]).launch();
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -147,6 +146,10 @@ Run the program by using `cargo run`. You should see the following in your
|
||||||
terminal:
|
terminal:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
🔧 Configured for development.
|
||||||
|
=> listening: localhost:8000
|
||||||
|
=> logging: Normal
|
||||||
|
=> session key: false
|
||||||
🛰 Mounting '/hello':
|
🛰 Mounting '/hello':
|
||||||
=> GET /hello/
|
=> GET /hello/
|
||||||
🚀 Rocket has launched from localhost:8000...
|
🚀 Rocket has launched from localhost:8000...
|
||||||
|
@ -155,8 +158,6 @@ terminal:
|
||||||
Finally, visit `http://localhost:8000` to see your first Rocket application in
|
Finally, visit `http://localhost:8000` to see your first Rocket application in
|
||||||
action.
|
action.
|
||||||
|
|
||||||
## "Hello, world!" Explained
|
|
||||||
|
|
||||||
# Introduction
|
# Introduction
|
||||||
|
|
||||||
Rocket provides a focused number of core primitives to build web servers and
|
Rocket provides a focused number of core primitives to build web servers and
|
||||||
|
@ -186,7 +187,6 @@ simple application. Let's begin.
|
||||||
#![plugin(rocket_codegen)]
|
#![plugin(rocket_codegen)]
|
||||||
|
|
||||||
extern crate rocket;
|
extern crate rocket;
|
||||||
use rocket::Rocket;
|
|
||||||
|
|
||||||
#[get("hi/<name>/<age>")]
|
#[get("hi/<name>/<age>")]
|
||||||
fn hello(name: &str, age: i8) -> String {
|
fn hello(name: &str, age: i8) -> String {
|
||||||
|
@ -204,9 +204,10 @@ fn not_found() -> &'static str {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
Rocket::ignite().mount("/", routes![hello, goodbye])
|
rocket::ignite()
|
||||||
.catch(errors![not_found])
|
.mount("/", routes![hello, goodbye])
|
||||||
.launch();
|
.catch(errors![not_found])
|
||||||
|
.launch();
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -239,23 +240,13 @@ request is of type `&'static str` whose value is `Hello, world!`.
|
||||||
|
|
||||||
Rocket route attributes have the following grammar:
|
Rocket route attributes have the following grammar:
|
||||||
|
|
||||||
```python
|
```ebnf
|
||||||
METHOD '(' PATH?, ('path' = PATH)? ('rank' = INT)? ('form' = STR)? ('format' = STR)? ')'
|
route := METHOD '(' path, kv_param* ')'
|
||||||
|
|
||||||
|
path := PATH
|
||||||
|
| 'path' = PATH
|
||||||
|
|
||||||
|
kv_param := 'rank' = INTEGER
|
||||||
|
| 'form' = STRING
|
||||||
|
| 'format' = STRING
|
||||||
```
|
```
|
||||||
|
|
||||||
## Outline
|
|
||||||
|
|
||||||
* Request/Response Cycle
|
|
||||||
* Routes and Handlers
|
|
||||||
* Mounting
|
|
||||||
* Dynamic Parameters
|
|
||||||
* Path Parameters
|
|
||||||
* Colliding and Ranks
|
|
||||||
* FromParam
|
|
||||||
* FromSegments
|
|
||||||
* FromRequest
|
|
||||||
* Responses
|
|
||||||
* Responder
|
|
||||||
* Contrib
|
|
||||||
* JSON
|
|
||||||
* Templates
|
|
||||||
|
|
|
@ -18,7 +18,6 @@ examples in [Rocket's git repository](github). Can you figure out what it does?
|
||||||
#![plugin(rocket_codegen)]
|
#![plugin(rocket_codegen)]
|
||||||
|
|
||||||
extern crate rocket;
|
extern crate rocket;
|
||||||
use rocket::Rocket;
|
|
||||||
|
|
||||||
#[get("/<name>/<age>")]
|
#[get("/<name>/<age>")]
|
||||||
fn hello(name: &str, age: u8) -> String {
|
fn hello(name: &str, age: u8) -> String {
|
||||||
|
@ -26,15 +25,19 @@ fn hello(name: &str, age: u8) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut rocket = Rocket::ignite();
|
rocket::ignite()
|
||||||
rocket.mount("/hello", routes![hello]);
|
.mount("/hello", routes![hello])
|
||||||
rocket.launch()
|
.launch();
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
If you were to run this application, your console would show:
|
If you were to run this application, your console would show:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
🔧 Configured for development.
|
||||||
|
=> listening: localhost:8000
|
||||||
|
=> logging: Normal
|
||||||
|
=> session key: false
|
||||||
🛰 Mounting '/hello':
|
🛰 Mounting '/hello':
|
||||||
=> GET /hello/<name>/<age>
|
=> GET /hello/<name>/<age>
|
||||||
🚀 Rocket has launched from localhost:8000...
|
🚀 Rocket has launched from localhost:8000...
|
||||||
|
@ -135,8 +138,8 @@ about the `route!` macro, see the [internals guide](guide/internals).
|
||||||
Let's look at lines 13 - 14 again, which we reproduce below:
|
Let's look at lines 13 - 14 again, which we reproduce below:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
let mut rocket = Rocket::ignite();
|
rocket::ignite()
|
||||||
rocket.mount(“/hello”, routes![hello]);
|
.mount(“/hello”, routes![hello])
|
||||||
```
|
```
|
||||||
|
|
||||||
Line 13 creates the new `Rocket` instance, and line 14 mounts the `hello` route
|
Line 13 creates the new `Rocket` instance, and line 14 mounts the `hello` route
|
||||||
|
|
Loading…
Reference in New Issue