Response maker for Flask with RFC Standards such as Link Headers
pip install Flask-Paginated-Response
To use Flask Paginated Response, build your response object with the PaginatedResponse class:
import json
from flask_paginated_response import PaginatedResponse
@app.route('/')
def index(self):
per_page = 10
current_page = 0
total = 18
response = {'status': 'online'}
return PaginatedResponse(per_page, current_page, total, json.dumps(response))
Using PaginatedResponse class, you will get this response headers:
HTTP/1.0 200 OK
X-Total-Count: 18
Link: <http://localhost:5000/?size=3&page=5>; rel="last", <http://localhost:5000/?size=3&page=1>; rel="next"
Content-Type: application/json
Content-Length: 515
Server: Werkzeug/0.11.10 Python/2.7.10
Date: Thu, 21 Jul 2016 14:08:23 GMT
- PaginatedResponse: Extending the full Response __init__ method with all available kwargs
- PaginatedResponse: Created PaginatedResponse class