Simple Serializers for API validations
Project description
# Flask-Simple-Serializer
Simple Serializer to valid API request
### Usage
```python
# my_app.serializers.py
from flask_simple_serializer.serializers import Serializer
from flask_simple_serializer import StringField, BooleanField, EmailField, validators
class Userserializer(Serializer):
username = StringField('Username')
email = EmailField('Email Address', [validators.Length(min=4, max=25)])
accept_rules = BooleanField('I accept the site rules', [validators.InputRequired()])
def create_user(self):
pass
# my_app.views.py
from flask_simple_serializer.response import Response
from flask_simple_serializer.status_code import HTTP_200_OK, HTTP_400_BAD_REQUEST
from my_app.serializes import Userserializer
@site.route('/some_route/')
def user_registration():
serializer = UserSerializer(request.json)
if serializer.is_valid()
# Do something
serializer.create_user()
return Response(status_code=HTTP_200_OK)
return Response(serializer.errors, status_code=HTTP_400_BAD_REQUEST)
```
### TODO
- Model Serializer
- Serializer that accept Model instance (SqlAlchemy)
- Improve Documentation
- Custom Felds
- Parse request decorators
- Test for Response and Status Codes
Simple Serializer to valid API request
### Usage
```python
# my_app.serializers.py
from flask_simple_serializer.serializers import Serializer
from flask_simple_serializer import StringField, BooleanField, EmailField, validators
class Userserializer(Serializer):
username = StringField('Username')
email = EmailField('Email Address', [validators.Length(min=4, max=25)])
accept_rules = BooleanField('I accept the site rules', [validators.InputRequired()])
def create_user(self):
pass
# my_app.views.py
from flask_simple_serializer.response import Response
from flask_simple_serializer.status_code import HTTP_200_OK, HTTP_400_BAD_REQUEST
from my_app.serializes import Userserializer
@site.route('/some_route/')
def user_registration():
serializer = UserSerializer(request.json)
if serializer.is_valid()
# Do something
serializer.create_user()
return Response(status_code=HTTP_200_OK)
return Response(serializer.errors, status_code=HTTP_400_BAD_REQUEST)
```
### TODO
- Model Serializer
- Serializer that accept Model instance (SqlAlchemy)
- Improve Documentation
- Custom Felds
- Parse request decorators
- Test for Response and Status Codes
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file Flask-Simple-Serializer-1.1.3.tar.gz
.
File metadata
- Download URL: Flask-Simple-Serializer-1.1.3.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09a81c085180b19cf8ea0783a267e6776cf7a96e75b49befe809773f7d36ec25 |
|
MD5 | 75a3a2de2fc827117a0e86d045ed358b |
|
BLAKE2b-256 | 4fc1892681628b1c471e7f5d1e1100f55de6bc5108facede2ef71580418ffd6e |
File details
Details for the file Flask_Simple_Serializer-1.1.3-py3-none-any.whl
.
File metadata
- Download URL: Flask_Simple_Serializer-1.1.3-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e76d6cb6e08c3b2567cfdcb66eaf6b5afd467d6dc6fed04d0bcfa00189301f2 |
|
MD5 | 8f834bdb0c3f937c1b2483241395e2ae |
|
BLAKE2b-256 | 9313293113045578f32fb4f51f235f391162cdafc4119a6179ff904300e621e6 |