From a1e9dedee0f6c0ea3bfc549c6bd2db90411fdc73 Mon Sep 17 00:00:00 2001 From: Steven Loria Date: Mon, 7 Jan 2019 19:11:34 +0900 Subject: [PATCH] Add webargs-starlette to Third Party Packages page (#306) --- docs/third-party-packages.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/docs/third-party-packages.md b/docs/third-party-packages.md index 99f6abf5..bc89b72c 100644 --- a/docs/third-party-packages.md +++ b/docs/third-party-packages.md @@ -25,6 +25,42 @@ That library aims to bring a layer on top of Starlette framework to provide usef * **Starlette ASGI** objects like `Request`, `Response`, `Session` and so on are defined as components and ready to be injected in your endpoints. +### webargs-starlette + + +Link: https://github.com/sloria/webargs-starlette + +Declarative request parsing and validation for Starlette, built on top +of [webargs](https://github.com/marshmallow-code/webargs). + +Allows you to parse querystring, JSON, form, headers, and cookies using +type annotations. + +```python +import uvicorn +from starlette.applications import Starlette +from starlette.responses import JSONResponse +from webargs_starlette import use_annotations + +app = Starlette() + + +@app.route("/") +@use_annotations(locations=("query",)) +async def index(request, name: str = "World"): + return JSONResponse({"Hello": name}) + + +if __name__ == "__main__": + uvicorn.run(app, port=5000) + +# curl 'http://localhost:5000/' +# {"Hello": "World"} +# curl 'http://localhost:5000/?name=Ada' +# {"Hello": "Ada"} +``` + + ## Frameworks ### Responder