Re:New Python REST API and CLI micro-framework
by BrandonHoffman on Friday February 19, 2016 @09:22AM
(#11133567)
I'm a contributor to the hug project.
we are currently working on a way of doing this which should be released to the development version this week and will be released with version 2.0
basically the modification would allow you to create a new type which has multiple predefined fields. like so:
class User(Type):
username = Chain(text, LongerThan(10))
password = Chain(text, LongerThan(10))
After creating this type you could then use it as a type as normal def stuff(arg1: int, arg2: User):
return 'Ok'
Re:New Python REST API and CLI micro-framework
by kstrauser on Friday February 19, 2016 @11:34AM
(#11134492)
May I make a suggestion? Please, PLEASE use a standardized Python modeling tool like Schematics, Marshmallow, etc. as your description language. Then your users can use the same models for their REST framework as for their ORM and everything else.
I'm begging: please do not reinvent this. Just don't.
Re:New Python REST API and CLI micro-framework
by timothycrosley on Friday February 19, 2016 @11:41AM
(#11134556)
kstrauser: Hug supports marshmallow! Right now, you can use Marshmallow types out of the box for any API call just set the Marshmallow type as the type after the annotation and it will work and validate as expected :)
One question, what would be the recommended way to define complex data types? E.g.
where arg2 would be a dictionary that should contain specific, predefined fields? This might also instead be a general question about Python type hinting