File: route-custom-method.rs

package info (click to toggle)
rust-actix-web-codegen 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 272 kB
  • sloc: makefile: 2
file content (37 lines) | stat: -rw-r--r-- 1,131 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use std::str::FromStr;

use actix_web::http::Method;
use actix_web_codegen::route;

#[route("/single", method = "CUSTOM")]
async fn index() -> String {
    "Hello Single!".to_owned()
}

#[route("/multi", method = "GET", method = "CUSTOM")]
async fn custom() -> String {
    "Hello Multi!".to_owned()
}

#[actix_web::main]
async fn main() {
    use actix_web::App;

    let srv = actix_test::start(|| App::new().service(index).service(custom));

    let request = srv.request(Method::GET, srv.url("/"));
    let response = request.send().await.unwrap();
    assert!(response.status().is_client_error());

    let request = srv.request(Method::from_str("CUSTOM").unwrap(), srv.url("/single"));
    let response = request.send().await.unwrap();
    assert!(response.status().is_success());

    let request = srv.request(Method::GET, srv.url("/multi"));
    let response = request.send().await.unwrap();
    assert!(response.status().is_success());

    let request = srv.request(Method::from_str("CUSTOM").unwrap(), srv.url("/multi"));
    let response = request.send().await.unwrap();
    assert!(response.status().is_success());
}