aiohttp simple pydantic validator
Project description
aiohttp-validator
aiohttp simple pydantic http request validator
Installation
pip install aiohttp-validator
A Simple Example
from typing import Any, Dict, List
import pydantic
from aiohttp import web
import aiohttp_validator as validator
routes = web.RouteTableDef()
class RequestHeaders(pydantic.BaseModel):
requestId: str
timestamp: float = 0.0
@routes.get('/')
@validator.validated()
async def simple_get(request: web.Request, headers: RequestHeaders, offset: int = 0):
assert isinstance(headers, RequestHeaders)
assert isinstance(offset, int)
return web.Response()
@routes.post('/{path}')
@validator.validated()
async def simple_post(request: web.Request, body: Dict[str, Any], path: str, offset: int, limit: int = 10):
assert isinstance(body, dict)
assert isinstance(path, str)
assert isinstance(offset, int)
assert isinstance(limit, int)
return web.Response()
class SubModel(pydantic.BaseModel):
l: List[str]
i: int
class Body(pydantic.BaseModel):
i: int
f: float
sub: SubModel
@routes.post('/{path1}/{path2}')
@validator.validated()
async def pydantic_body(request: web.Request, body: Body, path1: str, path2: int, pages: List[int]):
assert isinstance(body, Body)
assert isinstance(path1, str)
assert isinstance(path2, int)
assert isinstance(pages, list)
return web.Response()
app = web.Application()
app.add_routes(routes)
web.run_app(app, port=8080)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file aiohttp-validator-0.1.1.tar.gz
.
File metadata
- Download URL: aiohttp-validator-0.1.1.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.10.2 Linux/5.11.0-1027-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74d1880175cf8efe8eaa50d14977881000837add2ae2161fdf33e762a2f1b0e6 |
|
MD5 | 963622f36e1e295f4c8a1a5e2ee133cc |
|
BLAKE2b-256 | 89ea97157865bb79aa3ab3c756118776f4d40694bb3fb568224cddb47d9444d0 |
File details
Details for the file aiohttp_validator-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: aiohttp_validator-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.10.2 Linux/5.11.0-1027-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c6fa51e7b3a1508b03a860ed8657fa861b266eb4d783de2b16df5479682b458 |
|
MD5 | 8b107592d562b56980cdba7c659d7f01 |
|
BLAKE2b-256 | 2b55c112c96792f8542592145333fbbb45a8c47694975ea09b8e5565ff1583dc |