https://github.com/multimeric/marshmallow-jsonapi-webargs
Schemas for JSON API request parameters. Works along with marshmallow-jsonapi, which parses JSON request bodies
https://github.com/multimeric/marshmallow-jsonapi-webargs
Last synced: 12 months ago
JSON representation
Schemas for JSON API request parameters. Works along with marshmallow-jsonapi, which parses JSON request bodies
- Host: GitHub
- URL: https://github.com/multimeric/marshmallow-jsonapi-webargs
- Owner: multimeric
- License: lgpl-3.0
- Created: 2019-10-07T03:38:07.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-10-10T06:14:12.000Z (over 6 years ago)
- Last Synced: 2025-03-21T05:23:34.802Z (about 1 year ago)
- Language: Python
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Marshmallow JSON API Webargs
## Installation
```bash
pip install marshmallow-jsonapi-webargs
```
## Usage
Create a parser that adds in an improved query string logic:
```python
import marshmallow_jsonapi_webargs as jaw
from webargs.flaskparser import FlaskParser
class FlaskJsonApiParser(jaw.NestedQueryParserMixin, FlaskParser):
pass
parser = FlaskJsonApiParser()
```
Create the schema using some combination of the provided fields, according to which fields your API supports:
```python
from marshmallow import Schema
import marshmallow_jsonapi_webargs as jaw
class JsonApiRequestSchema(Schema):
sort = jaw.Sort()
include = jaw.Include()
fields = jaw.Fields()
page = jaw.PagePagination()
filter = jaw.Filter()
```
Use the schema to define your request format
```python
@parser.use_args(JsonApiRequestSchema())
def greet(args):
return 'You requested to include these relationships: ' + ', '.join(args['include'])
```
## Tests
To run the tests:
* Clone the repo:
```
git clone git@github.com:TMiguelT/marshmallow-jsonapi-webargs.git
cd marshmallow-jsonapi-webargs
```
* Install the test dependencies:
```bash
pip install '.[dev]'
```
* Run the tests:
```bash
pytest test.py
```