Skip to content

Commit

Permalink
Garde actix web, a garde wrapper for actix web
Browse files Browse the repository at this point in the history
  • Loading branch information
rlebran committed Sep 1, 2023
1 parent abd5dab commit 967f264
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Actix-web-garde build
name: garde-actix-web build

on:
pull_request:
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "actix-web-garde"
name = "garde-actix-web"
description = "Actix-web garde wrapper"
readme = "README.md"
keywords = ["garde", "actix", "actix-web", "validation"]
Expand All @@ -8,8 +8,8 @@ version = "0.1.0"

authors = ["Netwo <oss@netwo.com>"]
edition = "2021"
repository = "https://github.com/netwo-io/actix-web-garde"
documentation = "https://docs.rs/actix-web-garde/"
repository = "https://github.com/netwo-io/garde-actix-web"
documentation = "https://docs.rs/garde-actix-web/"
license = "MIT"
rust-version = "1.71"

Expand Down
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
# Actix-web-garde &emsp; [![Documentation]][docs.rs] [![Latest Version]][crates.io] [![Build Status]][build]
# Garde-actix-web &emsp; [![Documentation]][docs.rs] [![Latest Version]][crates.io] [![Build Status]][build]


[docs.rs]: https://docs.rs/actix-web-garde/latest/actix-web-garde/
[crates.io]: https://crates.io/crates/actix-web-garde
[build]: https://github.com/rlebran-netwo/actix-web-garde/actions/workflows/build.yaml?branch=main
[Documentation]: https://img.shields.io/docsrs/actix-web-garde
[Latest Version]: https://img.shields.io/crates/v/actix-web-garde.svg
[Build Status]: https://github.com/rlebran-netwo/actix-web-garde/actions/workflows/build.yaml/badge.svg?branch=main
[docs.rs]: https://docs.rs/garde-actix-web/latest/garde-actix-web/
[crates.io]: https://crates.io/crates/garde-actix-web
[build]: https://github.com/rlebran-netwo/garde-actix-web/actions/workflows/build.yaml?branch=main
[Documentation]: https://img.shields.io/docsrs/garde-actix-web
[Latest Version]: https://img.shields.io/crates/v/garde-actix-web.svg
[Build Status]: https://github.com/rlebran-netwo/garde-actix-web/actions/workflows/build.yaml/badge.svg?branch=main

Actix-web wrapper for [garde](https://github.com/jprochazk/garde), a Rust validation library.

- [Installation](#installation)
- [Usage example](#usage-example)
- [Feature flags](#feature-flags)
- [About us](#about-us)

### Installation

```toml
[dependencies]
garde = "0.14"
actix-web-garde = "0.1.0"
garde-actix-web = "0.1.0"
```

### Usage example

Simply use `actix-web-garde` exposed types as a drop in for actix types.
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 (`actix_web_garde::web::QueryConfig` in place of `actix_web::web::QueryConfig` for example).
Custom error handling can be implemented with an extractor config (`garde_actix_web::web::QueryConfig` in place of `actix_web::web::QueryConfig` for example).

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

#[derive(Validate)]
Expand All @@ -59,3 +60,10 @@ Context needs to be provided through actix's `data` or `app_data`, if not found
| name | description | extra dependencies |
|------------|---------------------------------------------------------------|----------------------------------------------------------------------------------------------|
| `serde_qs` | Enables the usage of `garde` for `serde_qs::actix::QsQuery<T>` | [`serde_qs`](https://crates.io/crates/serde_qs) |


### About us

Netwo

[**We are recruiting !**](https://www.netwo.io/carriere)
4 changes: 2 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Error exposed by actix-web-garde
//! Error exposed by garde-actix-web
//!
//! Custom error handlers (provided through the divers configs) should map from an `actix_web_garde::error::Error` to an `actix_web::error::Error`
//! Custom error handlers (provided through the divers configs) should map from an `garde_actix_web::error::Error` to an `actix_web::error::Error`
use actix_web::error::{JsonPayloadError, PathError, QueryPayloadError, UrlencodedError};
use actix_web::http::StatusCode;
use actix_web::{HttpResponse, ResponseError};
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
//! ```toml
//! [dependencies]
//! garde = "0.14"
//! actix-web-garde = "0.1.0"
//! garde-actix-web = "0.1.0"
//! ```
//!
//! # Usage example
//!
//! Simply use `actix-web-garde` exposed types as a drop in for actix types.
//! 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 (`actix_web_garde::web::QueryConfig` in place of `actix_web::web::QueryConfig` for example).
//! Custom error handling can be implemented with an extractor config (`garde_actix_web::web::QueryConfig` in place of `actix_web::web::QueryConfig` for example).
//!
//! ```rust
//! use actix_web::HttpResponse;
//! // instead of actix_web::web::Path
//! use actix_web_garde::web::Path;
//! use garde_actix_web::web::Path;
//! use garde::Validate;
//!
//! #[derive(Validate)]
Expand Down
2 changes: 1 addition & 1 deletion src/web/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ where
type FormErrHandler = Option<Rc<dyn Fn(crate::error::Error, &HttpRequest) -> Error>>;

/// Replacement for [actix_web::web::FormConfig](https://docs.rs/actix-web/latest/actix_web/web/struct.FormConfig.html)
/// Error handler must map from an `actix_web_garde::error::Error`
/// Error handler must map from an `garde_actix_web::error::Error`
#[derive(Clone)]
pub struct FormConfig {
limit: usize,
Expand Down
2 changes: 1 addition & 1 deletion src/web/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ where
type JsonErrorHandler = Option<Arc<dyn Fn(crate::error::Error, &HttpRequest) -> Error + Send + Sync>>;

/// Replacement for [actix_web::web::JsonConfig](https://docs.rs/actix-web/latest/actix_web/web/struct.JsonConfig.html)
/// Error handler must map from an `actix_web_garde::error::Error`
/// Error handler must map from an `garde_actix_web::error::Error`
#[derive(Clone)]
pub struct JsonConfig {
limit: usize,
Expand Down
2 changes: 1 addition & 1 deletion src/web/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ where
}

/// Replacement for [actix_web::web::PathConfig](https://docs.rs/actix-web/latest/actix_web/web/struct.PathConfig.html)
/// Error handler must map from an `actix_web_garde::error::Error`
/// Error handler must map from an `garde_actix_web::error::Error`
#[derive(Clone, Default)]
pub struct PathConfig {
#[allow(clippy::type_complexity)]
Expand Down
2 changes: 1 addition & 1 deletion src/web/qs_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ where
}

/// Replacement for [serde_qs::actix::QsQueryConfig](https://docs.rs/serde_qs/latest/serde_qs/actix/struct.QsQueryConfig.html)
/// Error handler must map from an `actix_web_garde::error::Error`
/// Error handler must map from an `garde_actix_web::error::Error`
#[derive(Default)]
pub struct QsQueryConfig {
#[allow(clippy::type_complexity)]
Expand Down
2 changes: 1 addition & 1 deletion src/web/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ where
}

/// Replacement for [actix_web::web::QueryConfig](https://docs.rs/actix-web/latest/actix_web/web/struct.QueryConfig.html)
/// Error handler must map from an `actix_web_garde::error::Error`
/// Error handler must map from an `garde_actix_web::error::Error`
#[derive(Clone, Default)]
pub struct QueryConfig {
#[allow(clippy::type_complexity)]
Expand Down

0 comments on commit 967f264

Please sign in to comment.