Struct actix_web::dev::Route [] [src]

pub struct Route<S> { /* fields omitted */ }

Resource route definition

Route uses builder-like pattern for configuration. If handler is not explicitly set, default 404 Not Found handler is used.

Methods

impl<S: 'static> Route<S>
[src]

Important traits for &'a mut W
[src]

Add match predicate to route.

App::new().resource("/path", |r| {
    r.route()
        .filter(pred::Get())
        .filter(pred::Header("content-type", "text/plain"))
        .f(|req| HttpResponse::Ok())
})

[src]

Set handler object. Usually call to this method is last call during route configuration, so it does not return reference to self.

[src]

Set handler function. Usually call to this method is last call during route configuration, so it does not return reference to self.

[src]

Set async handler function.

[src]

Set handler function, use request extractor for parameters.

#[macro_use] extern crate serde_derive;
use actix_web::{http, App, Path, Result};

#[derive(Deserialize)]
struct Info {
    username: String,
}

/// extract path info using serde
fn index(info: Path<Info>) -> Result<String> {
    Ok(format!("Welcome {}!", info.username))
}

fn main() {
    let app = App::new().resource(
        "/{username}/index.html", // <- define path parameters
        |r| r.method(http::Method::GET).with(index),
    ); // <- use `with` extractor
}

It is possible to use tuples for specifing multiple extractors for one handler function.

#[macro_use] extern crate serde_derive;
use actix_web::{http, App, Json, Path, Query, Result};

#[derive(Deserialize)]
struct Info {
    username: String,
}

/// extract path info using serde
fn index(
    info: (Path<Info>, Query<HashMap<String, String>>, Json<Info>),
) -> Result<String> {
    Ok(format!("Welcome {}!", info.0.username))
}

fn main() {
    let app = App::new().resource(
        "/{username}/index.html", // <- define path parameters
        |r| r.method(http::Method::GET).with(index),
    ); // <- use `with` extractor
}

[src]

Set async handler function, use request extractor for parameters. Also this method needs to be used if your handler function returns impl Future<>

#[macro_use] extern crate serde_derive;
use actix_web::{http, App, Error, Path};
use futures::Future;

#[derive(Deserialize)]
struct Info {
    username: String,
}

/// extract path info using serde
fn index(info: Path<Info>) -> Box<Future<Item = &'static str, Error = Error>> {
    unimplemented!()
}

fn main() {
    let app = App::new().resource(
        "/{username}/index.html", // <- define path parameters
        |r| r.method(http::Method::GET).with_async(index),
    ); // <- use `with` extractor
}

Trait Implementations

impl<S: 'static> Default for Route<S>
[src]

[src]

Returns the "default value" for a type. Read more

Auto Trait Implementations

impl<S> !Send for Route<S>

impl<S> !Sync for Route<S>