dc5ef6a421
Added `error` decorator and `errors` macro. The current idea is that you can have "catchers" for all valid errors code (in range [400, 500). At the moment, catchers are just request handlers, and the decorator expected an empty function signature for the error handler. Obviously, this is pretty useless. Not sure on what the API should be here. But, progress. Oh, one more thing: who should handle forwarding a request to a catcher? Probably not the router. So, the main Rocket should? |
||
---|---|---|
docs | ||
examples | ||
lib | ||
macros | ||
scripts | ||
.gitignore | ||
.travis.yml | ||
README.md |
Rocket
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:
#![feature(plugin)]
#![plugin(rocket_macros)]
extern crate rocket;
use rocket::Rocket;
#[route(GET, path = "/hello/<name>/<age>")]
fn hello(name: &str, age: i8) -> String {
format!("Hello, {} year old named {}!", age, name)
}
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
Then visit localhost:8000/hello/{some_name}
, replacing {some_name}
with some
name.
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