12 releases (breaking)

0.10.0 Sep 9, 2024
0.9.0 Jul 5, 2024
0.8.0 Jul 3, 2024
0.6.0 Feb 29, 2024
0.2.0 Oct 3, 2023

#595 in Web programming

Download history 596/week @ 2024-08-21 568/week @ 2024-08-28 879/week @ 2024-09-04 724/week @ 2024-09-11 700/week @ 2024-09-18 762/week @ 2024-09-25 770/week @ 2024-10-02 744/week @ 2024-10-09 469/week @ 2024-10-16 561/week @ 2024-10-23 589/week @ 2024-10-30 653/week @ 2024-11-06 650/week @ 2024-11-13 588/week @ 2024-11-20 480/week @ 2024-11-27 509/week @ 2024-12-04

2,366 downloads per month
Used in 3 crates (2 directly)

MIT license

72KB
1.5K SLoC

Garde-actix-web   Documentation Latest Version Build Status

Actix-web wrapper for garde, a Rust validation library.

Installation

[dependencies]
garde = "0.20"
garde-actix-web = "0.9"

Usage example

Simply use garde-actix-web exposed types as a drop in for actix types.

Your types must implement Validate from garde. Validation happens during actix's FromRequest invocation.

If payload is invalid, a 400 error is returned (404 for Path).

Custom error handling can be implemented with an extractor config (garde_actix_web::web::QueryConfig in place of actix_web::web::QueryConfig for example).

use actix_web::HttpResponse;
// instead of actix_web::web::Path
use garde_actix_web::web::Path;
use garde::Validate;

#[derive(Validate)]
struct MyStruct<'a> {
  #[garde(ascii, length(min = 3, max = 25))]
  username: &'a str,
}

fn test(id: Path<MyStruct>) -> HttpResponse {
  todo!()
}

Context needs to be provided through actix's data or app_data, if not found default will be used instead.

Feature flags

name description extra dependencies
serde_qs Enables the usage of garde for serde_qs::actix::QsQuery<T> serde_qs

Compatibility matrix

garde version serde_qs version garde-actix-web-version
0.14 0.12 0.1.x
0.15 0.12 0.2.x
0.16 0.12 0.3.x
0.17 0.12 0.4.x
0.18 0.12 0.5.x, 0.6.x
0.18 0.13 0.7.x
0.19 0.13 0.8.x
0.20 0.13 0.9.x

About us

Garde-actix-web is provided by Netwo.

We use this crate for our internal needs and therefore are committed to its maintenance, however we cannot provide any additional guaranty. Use it at your own risks.

While we won't invest in any feature we don't need, we are open to accept any pull request you might propose.

We are a France based full-remote company operating in the telecom sector. If you are interested in learning more, feel free to visit our career page.

Dependencies

~16–28MB
~467K SLoC