Last active
April 9, 2019 11:50
-
-
Save shon/08fe2e06ddf4dcfb8caaf3bda935a7c2 to your computer and use it in GitHub Desktop.
Hug Bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# - hug version: 2.4.7 | |
# - marshmallow: 3.0.0rc4 | |
# - Python: 3.6.7 on Ubuntu 18.10 | |
import hug | |
from marshmallow import Schema, fields | |
class ItemSchema(Schema): | |
name = fields.Str() | |
id = fields.Int() | |
itemschema = hug.types.MarshmallowInputSchema(ItemSchema()) | |
@hug.post('/items/') | |
def create(item: itemschema): | |
return {} | |
# Start hug `hug -f schematest.py` | |
# >> import requests | |
# >> response = requests.post('http://127.0.0.1:8000/items/', json={'item': {'name': 'snake', 'id': 19}}) | |
# >> print(response.json()) | |
# {'errors': {'item': 'id'}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment