added docs, tests and updates to changes.md

This commit is contained in:
edgerunnergit 2023-01-30 10:53:20 +05:30
parent 63d49febea
commit d358919902
5 changed files with 20 additions and 2 deletions

View File

@ -1,6 +1,7 @@
# Changes
## Unreleased - 2022-xx-xx
- Add support for Custom Methods with `#[route]` macro. [#2969]
## 4.1.0 - 2022-09-11

View File

@ -105,7 +105,7 @@ mod route;
/// ```
/// # use actix_web::HttpResponse;
/// # use actix_web_codegen::route;
/// #[route("/test", method = "GET", method = "HEAD")]
/// #[route("/test", method = "GET", method = "HEAD", method = "CUSTOM")]
/// async fn example() -> HttpResponse {
/// HttpResponse::Ok().finish()
/// }

View File

@ -86,7 +86,13 @@ async fn get_param_test(_: web::Path<String>) -> impl Responder {
HttpResponse::Ok()
}
#[route("/multi", method = "GET", method = "POST", method = "HEAD")]
#[route(
"/multi",
method = "GET",
method = "POST",
method = "HEAD",
method = "CREATE"
)]
async fn route_test() -> impl Responder {
HttpResponse::Ok()
}

View File

@ -8,6 +8,7 @@
- Add rudimentary redirection service at `web::redirect()` / `web::Redirect`. [#1961]
- Add `guard::Acceptable` for matching against `Accept` header mime types. [#2265]
- Add fallible versions of test helpers: `try_call_service`, `try_call_and_read_body_json`, `try_read_body`, and `try_read_body_json`. [#2961]
- Add `guard::Custom()` for handling `#[route]` macro with custom Methods. . [#2969]
### Fixed
- Add `Allow` header to `Resource`'s default responses when no routes are matched. [#2949]

View File

@ -339,6 +339,16 @@ method_guard!(Connect, CONNECT);
method_guard!(Patch, PATCH);
method_guard!(Trace, TRACE);
///
/// # Examples
#[doc = "The route in this example will respond to all uppercase ASCII requests."]
/// ```
/// use actix_web::{guard, web, HttpResponse};
///
/// web::route()
#[doc = " .guard(guard::Custom(\"HELLO\"))"]
/// .to(|| HttpResponse::Ok());
/// ```
#[allow(non_snake_case)]
pub fn Custom(custom_method: &str) -> impl Guard {
MethodGuard(HttpMethod::from_bytes(custom_method.as_bytes()).unwrap())