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)]
|
||||
|
||||
extern crate rocket;
|
||||
use rocket::Rocket;
|
||||
|
||||
#[get("/")]
|
||||
fn hello() -> &'static str {
|
||||
|
@ -139,7 +138,7 @@ fn hello() -> &'static str {
|
|||
}
|
||||
|
||||
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:
|
||||
|
||||
```sh
|
||||
🔧 Configured for development.
|
||||
=> listening: localhost:8000
|
||||
=> logging: Normal
|
||||
=> session key: false
|
||||
🛰 Mounting '/hello':
|
||||
=> GET /hello/
|
||||
🚀 Rocket has launched from localhost:8000...
|
||||
|
@ -155,8 +158,6 @@ terminal:
|
|||
Finally, visit `http://localhost:8000` to see your first Rocket application in
|
||||
action.
|
||||
|
||||
## "Hello, world!" Explained
|
||||
|
||||
# Introduction
|
||||
|
||||
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)]
|
||||
|
||||
extern crate rocket;
|
||||
use rocket::Rocket;
|
||||
|
||||
#[get("hi/<name>/<age>")]
|
||||
fn hello(name: &str, age: i8) -> String {
|
||||
|
@ -204,7 +204,8 @@ fn not_found() -> &'static str {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
Rocket::ignite().mount("/", routes![hello, goodbye])
|
||||
rocket::ignite()
|
||||
.mount("/", routes![hello, goodbye])
|
||||
.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:
|
||||
|
||||
```python
|
||||
METHOD '(' PATH?, ('path' = PATH)? ('rank' = INT)? ('form' = STR)? ('format' = STR)? ')'
|
||||
```ebnf
|
||||
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)]
|
||||
|
||||
extern crate rocket;
|
||||
use rocket::Rocket;
|
||||
|
||||
#[get("/<name>/<age>")]
|
||||
fn hello(name: &str, age: u8) -> String {
|
||||
|
@ -26,15 +25,19 @@ fn hello(name: &str, age: u8) -> String {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let mut rocket = Rocket::ignite();
|
||||
rocket.mount("/hello", routes![hello]);
|
||||
rocket.launch()
|
||||
rocket::ignite()
|
||||
.mount("/hello", routes![hello])
|
||||
.launch();
|
||||
}
|
||||
```
|
||||
|
||||
If you were to run this application, your console would show:
|
||||
|
||||
```sh
|
||||
🔧 Configured for development.
|
||||
=> listening: localhost:8000
|
||||
=> logging: Normal
|
||||
=> session key: false
|
||||
🛰 Mounting '/hello':
|
||||
=> GET /hello/<name>/<age>
|
||||
🚀 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:
|
||||
|
||||
```rust
|
||||
let mut rocket = Rocket::ignite();
|
||||
rocket.mount(“/hello”, routes![hello]);
|
||||
rocket::ignite()
|
||||
.mount(“/hello”, routes![hello])
|
||||
```
|
||||
|
||||
Line 13 creates the new `Rocket` instance, and line 14 mounts the `hello` route
|
||||
|
|
Loading…
Reference in New Issue