From 967f264feac7f000f0dd770ba662130accb49737 Mon Sep 17 00:00:00 2001 From: Romain Lebran Date: Fri, 1 Sep 2023 15:23:17 +0200 Subject: [PATCH] Garde actix web, a garde wrapper for actix web --- .github/workflows/build.yaml | 2 +- Cargo.toml | 6 +++--- README.md | 30 +++++++++++++++++++----------- src/error.rs | 4 ++-- src/lib.rs | 8 ++++---- src/web/form.rs | 2 +- src/web/json.rs | 2 +- src/web/path.rs | 2 +- src/web/qs_query.rs | 2 +- src/web/query.rs | 2 +- 10 files changed, 34 insertions(+), 26 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 5d03b1a..fa1ff6e 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,4 +1,4 @@ -name: Actix-web-garde build +name: garde-actix-web build on: pull_request: diff --git a/Cargo.toml b/Cargo.toml index 8debed3..6baea18 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] @@ -8,8 +8,8 @@ version = "0.1.0" authors = ["Netwo "] 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" diff --git a/README.md b/README.md index e7909bb..319567e 100644 --- a/README.md +++ b/README.md @@ -1,41 +1,42 @@ -# Actix-web-garde   [![Documentation]][docs.rs] [![Latest Version]][crates.io] [![Build Status]][build] +# Garde-actix-web   [![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)] @@ -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` | [`serde_qs`](https://crates.io/crates/serde_qs) | + + +### About us + +Netwo + +[**We are recruiting !**](https://www.netwo.io/carriere) diff --git a/src/error.rs b/src/error.rs index a54e9c5..59548f0 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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}; diff --git a/src/lib.rs b/src/lib.rs index 4eb3291..e04abb5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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)] diff --git a/src/web/form.rs b/src/web/form.rs index 63494f1..3d2ba59 100644 --- a/src/web/form.rs +++ b/src/web/form.rs @@ -73,7 +73,7 @@ where type FormErrHandler = Option 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, diff --git a/src/web/json.rs b/src/web/json.rs index b80b4ef..cde82b1 100644 --- a/src/web/json.rs +++ b/src/web/json.rs @@ -90,7 +90,7 @@ where type JsonErrorHandler = Option 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, diff --git a/src/web/path.rs b/src/web/path.rs index 6176993..8068b94 100644 --- a/src/web/path.rs +++ b/src/web/path.rs @@ -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)] diff --git a/src/web/qs_query.rs b/src/web/qs_query.rs index f65f0aa..3baf015 100644 --- a/src/web/qs_query.rs +++ b/src/web/qs_query.rs @@ -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)] diff --git a/src/web/query.rs b/src/web/query.rs index 0864973..1eb333d 100644 --- a/src/web/query.rs +++ b/src/web/query.rs @@ -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)]