mirror of
https://github.com/fafhrd91/actix-web
synced 2025-06-26 15:07:42 +02:00
routes
macro allowing multiple paths per handler (#2718)
* WIP: basic implementation for `routes` macro * chore: changelog, docs, tests * error on missing methods * Apply suggestions from code review Co-authored-by: Igor Aleksanov <popzxc@yandex.ru> * update test stderr expectation * add additional tests * fix stderr output * remove useless ResourceType this is dead code from back when .to and .to_async were different ways to add a service Co-authored-by: Igor Aleksanov <popzxc@yandex.ru> Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
committed by
GitHub
parent
c0d5d7bdb5
commit
8759d79b03
14
actix-web-codegen/tests/trybuild/routes-missing-args-fail.rs
Normal file
14
actix-web-codegen/tests/trybuild/routes-missing-args-fail.rs
Normal file
@ -0,0 +1,14 @@
|
||||
use actix_web_codegen::*;
|
||||
|
||||
#[routes]
|
||||
#[get]
|
||||
async fn index() -> String {
|
||||
"Hello World!".to_owned()
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() {
|
||||
use actix_web::App;
|
||||
|
||||
let srv = actix_test::start(|| App::new().service(index));
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
error: invalid service definition, expected #[get("<path>")]
|
||||
--> tests/trybuild/routes-missing-args-fail.rs:4:1
|
||||
|
|
||||
4 | #[get]
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: this error originates in the attribute macro `get` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: Invalid input for macro
|
||||
--> tests/trybuild/routes-missing-args-fail.rs:4:1
|
||||
|
|
||||
4 | #[get]
|
||||
| ^^^^^^
|
||||
|
||||
error[E0277]: the trait bound `fn() -> impl std::future::Future {index}: HttpServiceFactory` is not satisfied
|
||||
--> tests/trybuild/routes-missing-args-fail.rs:13:55
|
||||
|
|
||||
13 | let srv = actix_test::start(|| App::new().service(index));
|
||||
| ------- ^^^^^ the trait `HttpServiceFactory` is not implemented for `fn() -> impl std::future::Future {index}`
|
||||
| |
|
||||
| required by a bound introduced by this call
|
@ -0,0 +1,13 @@
|
||||
use actix_web_codegen::*;
|
||||
|
||||
#[routes]
|
||||
async fn index() -> String {
|
||||
"Hello World!".to_owned()
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() {
|
||||
use actix_web::App;
|
||||
|
||||
let srv = actix_test::start(|| App::new().service(index));
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
error: The #[routes] macro requires at least one `#[<method>(..)]` attribute.
|
||||
--> tests/trybuild/routes-missing-method-fail.rs:3:1
|
||||
|
|
||||
3 | #[routes]
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: this error originates in the attribute macro `routes` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0277]: the trait bound `fn() -> impl std::future::Future {index}: HttpServiceFactory` is not satisfied
|
||||
--> tests/trybuild/routes-missing-method-fail.rs:12:55
|
||||
|
|
||||
12 | let srv = actix_test::start(|| App::new().service(index));
|
||||
| ------- ^^^^^ the trait `HttpServiceFactory` is not implemented for `fn() -> impl std::future::Future {index}`
|
||||
| |
|
||||
| required by a bound introduced by this call
|
23
actix-web-codegen/tests/trybuild/routes-ok.rs
Normal file
23
actix-web-codegen/tests/trybuild/routes-ok.rs
Normal file
@ -0,0 +1,23 @@
|
||||
use actix_web_codegen::*;
|
||||
|
||||
#[routes]
|
||||
#[get("/")]
|
||||
#[post("/")]
|
||||
async fn index() -> String {
|
||||
"Hello World!".to_owned()
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() {
|
||||
use actix_web::App;
|
||||
|
||||
let srv = actix_test::start(|| App::new().service(index));
|
||||
|
||||
let request = srv.get("/");
|
||||
let response = request.send().await.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
|
||||
let request = srv.post("/");
|
||||
let response = request.send().await.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
}
|
Reference in New Issue
Block a user