Created
July 19, 2018 21:03
-
-
Save spooky/31a63d8c86edf831dd8cf19bc8be2ddb to your computer and use it in GitHub Desktop.
hug+datatypes
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
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