Skip to content

Instantly share code, notes, and snippets.

@shon
Last active April 9, 2019 11:50
Show Gist options
  • Save shon/08fe2e06ddf4dcfb8caaf3bda935a7c2 to your computer and use it in GitHub Desktop.
Save shon/08fe2e06ddf4dcfb8caaf3bda935a7c2 to your computer and use it in GitHub Desktop.
Hug Bug
# - 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