Attribute Macro patch
#[patch]
Expand description
Define a route for PATCH requests to a given path.
This is a shorthand for #[route(method = "PATCH", path = "...")]
.
§Example
use pavex::{patch, Response};
#[patch(path = "/users/{id}")]
pub async fn patch_user(/* */) -> Response {
// Patch user logic
// [...]
}
§Guide
Check out the “Routing” section of Pavex’s guide for a thorough introduction to routing in Pavex applications.
§Registration
You can register a PATCH route with your application in two ways:
- Use
Blueprint::route
to register a single route - Use
Blueprint::import
to import multiple routes in bulk
The #[patch]
macro generates a constant that you can use to refer to the
route when invoking Blueprint::route
.
§Arguments
The sections below provide an exhaustive list of all the arguments supported by the patch
macro:
§path
The path
argument specifies the URL path pattern that this route will match.
The path can contain dynamic parameter placeholders in the format {parameter_name}
.
Check out the guide on parameter extraction
for a detailed explanation.
§Example
use pavex::{patch, Response};
#[patch(path = "/users/{id}")]
// 👆 Path with parameter
pub async fn patch_user(/* */) -> Response {
// [...]
}
§id
By default, Pavex generates a constant named after your function
(converted to UPPER_SNAKE_CASE) that you can use when invoking Blueprint::route
.
The id
argument allows you to customize the name of the generated constant.
§Example
Using the default generated identifier:
use pavex::{patch, Response, Blueprint};
#[patch(path = "/users/{id}")]
pub async fn patch_user(/* */) -> Response {
// [...]
}
let mut bp = Blueprint::new();
// The generated constant is named `PATCH_USER`
bp.route(PATCH_USER);
Using a custom identifier:
use pavex::{patch, Response, Blueprint};
#[patch(path = "/users/{id}", id = "CUSTOM_ROUTE")]
// 👆 Custom identifier
pub async fn patch_user(id: u32) -> Response {
// [...]
}
let mut bp = Blueprint::new();
// Use the custom identifier when registering
bp.route(CUSTOM_ROUTE);