put

Attribute Macro put 

#[put]
Expand description

Define a route for PUT requests to a given path.

This is a shorthand for #[route(method = "PUT", path = "...")].

§Example

use pavex::{put, Response};

#[put(path = "/users/{id}")]
pub async fn put_user(/* */) -> Response {
    // Put 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 PUT route with your application in two ways:

The #[put] 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 put macro:

NameKindRequired
pathArgumentYes
idArgumentNo

§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::{put, Response};

#[put(path = "/users/{id}")]
//           👆 Path with parameter
pub async fn put_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::{put, Response, Blueprint};

#[put(path = "/users/{id}")]
pub async fn put_user(/* */) -> Response {
    // [...]
}

let mut bp = Blueprint::new();
// The generated constant is named `PUT_USER`
bp.route(PUT_USER);

Using a custom identifier:

use pavex::{put, Response, Blueprint};

#[put(path = "/users/{id}", id = "CUSTOM_ROUTE")]
//                           👆 Custom identifier
pub async fn put_user(id: u32) -> Response {
    // [...]
}

let mut bp = Blueprint::new();
// Use the custom identifier when registering
bp.route(CUSTOM_ROUTE);