2016-03-12 18:45:19 +00:00
|
|
|
# Rocket
|
2016-03-12 18:54:38 +00:00
|
|
|
|
|
|
|
Rocket is a work-in-progress web framework for Rust (nightly) with a focus on
|
|
|
|
ease-of-use, expressability, and speed. It currently does not work. But, when it
|
|
|
|
does, the following will be the canonical "Hello, world!" example:
|
|
|
|
|
|
|
|
```rust
|
|
|
|
#![feature(plugin)]
|
|
|
|
#![plugin(rocket_macros)]
|
|
|
|
|
|
|
|
extern crate rocket;
|
2016-03-15 03:46:55 +00:00
|
|
|
use rocket::Rocket;
|
2016-03-12 18:54:38 +00:00
|
|
|
|
2016-03-18 02:56:23 +00:00
|
|
|
#[route(GET, path = "/hello/<name>")]
|
|
|
|
fn hello(name: &'static str) -> String {
|
|
|
|
format!("Hello, {}!", name)
|
2016-03-12 18:54:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut rocket = Rocket::new("localhost", 8000);
|
|
|
|
rocket.mount_and_launch("/", routes![hello]);
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Rocket requires a nightly version of Rust as it makes heavy use of syntax
|
|
|
|
extensions. This also means that the first two unwieldly lines in the Rust file
|
|
|
|
above are required.
|
|
|
|
|
|
|
|
## Building
|
|
|
|
|
|
|
|
Try running the examples in the `examples/` folder. For instance, the following
|
|
|
|
sequence of commands builds the `Hello, world!` example:
|
|
|
|
|
|
|
|
```
|
|
|
|
cd examples/hello
|
|
|
|
cargo build
|
|
|
|
cargo run
|
|
|
|
```
|
|
|
|
|
2016-03-18 02:56:23 +00:00
|
|
|
Then visit `localhost:8000/hello/{some_name}`, replacing `{some_name}` with some
|
|
|
|
name.
|
|
|
|
|
2016-03-12 18:54:38 +00:00
|
|
|
### OS X
|
|
|
|
|
|
|
|
Apple has stopped shipping `openssl` with OS X.11. As such, if your build fails
|
|
|
|
compile, you'll need to install `openssl`, `cargo clean`, and then `cargo build`
|
|
|
|
again. Here are some lightweight instructions:
|
|
|
|
|
|
|
|
```
|
|
|
|
brew install openssl
|
|
|
|
brew link --force openssl
|
|
|
|
export OPENSSL_INCLUDE_DIR=`brew --prefix openssl`/include
|
|
|
|
export OPENSSL_LIB_DIR=`brew --prefix openssl`/lib
|
|
|
|
```
|
|
|
|
|