Struct canteen::Canteen[][src]

pub struct Canteen { /* fields omitted */ }

The primary struct provided by the library. The aim is to have a similar interface to Flask, the Python microframework.

Methods

impl Canteen
[src]

Creates a new Canteen instance.

Examples

use canteen::Canteen;

let cnt = Canteen::new();

Bind to an address on which to listen for connections

Examples

This example is not tested
use canteen::Canteen;

let mut cnt = Canteen::new();
cnt.bind(("127.0.0.1", 8080));

Adds a new route definition to be handled by Canteen.

Examples

use canteen::{Canteen, Request, Response, Method};
use canteen::utils;

fn handler(_: &Request) -> Response {
    utils::make_response("<b>Hello, world!</b>", "text/html", 200)
}

fn main() {
    let mut cnt = Canteen::new();
    cnt.add_route("/hello", &[Method::Get], handler);
}

Defines a default route for undefined paths.

Examples

use canteen::Canteen;
use canteen::utils;

let mut cnt = Canteen::new();
cnt.set_default(utils::err_404);

Creates the listener and starts a Canteen server's event loop.

Examples

use canteen::Canteen;

let mut cnt = Canteen::new();
cnt.run();

Trait Implementations

impl Handler for Canteen
[src]

Invoked when the socket represented by token is ready to be operated on. events indicates the specific operations that are ready to be performed. Read more

Invoked when a message has been received via the event loop's channel.

Invoked when a timeout has completed.

Invoked when EventLoop has been interrupted by a signal interrupt.

Invoked at the end of an event loop tick.

Auto Trait Implementations

impl Send for Canteen

impl !Sync for Canteen