[−][src]Function actix_web::web::resource
pub fn resource<P: 'static>(path: &str) -> Resource<P>
Create resource for a specific path.
Resources may have variable path segments. For example, a
resource with the path /a/{name}/c
would match all incoming
requests with paths such as /a/b/c
, /a/1/c
, or /a/etc/c
.
A variable segment is specified in the form {identifier}
,
where the identifier can be used later in a request handler to
access the matched value for that segment. This is done by
looking up the identifier in the Params
object returned by
HttpRequest.match_info()
method.
By default, each segment matches the regular expression [^{}/]+
.
You can also specify a custom regex in the form {identifier:regex}
:
For instance, to route GET
-requests on any route matching
/users/{userid}/{friend}
and store userid
and friend
in
the exposed Params
object:
use actix_web::{web, App, HttpResponse}; fn main() { let app = App::new().service( web::resource("/users/{userid}/{friend}") .route(web::get().to(|| HttpResponse::Ok())) .route(web::head().to(|| HttpResponse::MethodNotAllowed())) ); }