Crate edge [] [src]

Edge is a Web framework that aims to be simple to use, with the most common things you need out of the box. There are no plugins, the framework is not modular, but it is simple to use and easy to contribute to.

The crate exports the things that you often need from dependencies, such as headers (from hyper), cookies (from cookie) and JSON serialization (from serde_json).

Warning: this is a very early version, and the API is not fully stable yet.


In Edge you must define an application structure that contains the state of your application. You instantiate a container around this application, and associate GET/POST/... requests with given URLs to methods of your application. The container handles the routing and delegates calls to the appropriate methods.

Note that the state cannot be mutated, as is usual in Rust (and enforced by the underlying HTTP server this crate uses, a.k.a. Hyper). Any shared mutable variable must be wrapped in a Mutex.

Why another Web framework in Rust?

Because I wanted a simple Web framework with:

  1. everything I needed out of the box, like cookies and forms and templating, without having to dig up third-party crates,
  2. the possibility to describe my application as a struct, so that callbacks could use a state (even if just for configuration).

I hope you like this crate, if it misses something to fit your needs just open an issue or make a pull request!

And please keep in mind that the framework is in a (very) early stage :-)

Hello World

extern crate edge;

use edge::{Container, Request, Response, Status};
use edge::header::Server;
use std::io::Result;
use std::sync::Mutex;

struct MyApp {
    version: &'static str,
    counter: Mutex<u32>

impl MyApp {
    fn home(&self, _req: &mut Request, mut res: Response) -> Result<()> {
        let cnt = {
            let mut counter = self.counter.lock().unwrap();
            *counter += 1;

        res.header(Server(format!("Edge version {}", self.version)));
        res.send(format!("Hello, world! {} visits", cnt))

fn main() {
    let app = MyApp { version: "0.1", counter: Mutex::new(0) };
    let mut cter = Container::new(app);
    cter.get("/", MyApp::home);



Headers container, and common header fields.


JSON Value



Container of an application.


A request, with a path, query, and fragment (accessor methods not yet implemented for the last two).


A route is an absolute URL pattern with a leading slash, and segments separated by slashes.



An HTTP status code (status-code in RFC 7230 et al.).

Type Definitions


Signature for a callback method