Skip to content

Instantly share code, notes, and snippets.

@spooky
Created July 19, 2018 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spooky/31a63d8c86edf831dd8cf19bc8be2ddb to your computer and use it in GitHub Desktop.
Save spooky/31a63d8c86edf831dd8cf19bc8be2ddb to your computer and use it in GitHub Desktop.
hug+datatypes
from dataclasses import dataclass, field, asdict
import hug
@dataclass
class Paged:
items: list = field(default_factory=list)
total: int = 0
@dataclass
class AThing:
id: int
name: str
@dataclass
class AnotherThing:
thing: AThing
name: str
@hug.get('/items')
def items(skip: hug.types.greater_than(-1)=0, take: hug.types.in_range(0, 101)=10):
items = Paged(total=10, items=[AnotherThing(name='Yo', thing=AThing(id=1, name='man'))])
return asdict(items)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment