Abstracts HTTP request input handling, providing an easy interface for data hydration and validation Based on https://github.com/LinioIT/input
$ pip install fractal_input
from fractal_input import InputHandler, DatetimeNode, ListNode
class UserHandler(InputHandler):
def define(self):
user = self.add('user', User)
user.add('name', 'string')
user.add('email', 'string')
user.add('age', 'integer', {'required': False})
user.add('createdAt', DatetimeNode('%m/%d/%y %H:%M:%S'))
address = user.add('address', Address)
address.add('street', 'string')
telephone = user.add('telephones', ListNode(Telephone))
telephone.add('number', 'string')
dict_data = {
'user': {
'name': 'James',
'email': '[email protected]',
'age': 20
}
}
input = UserHandler()
input.bind(dict_data)
if not input.is_valid():
print(input.get_error_as_string())
user = input.get_data()['user']