Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vrcmarcos/flask-filtered-response
Add filter capability to JSON responses
https://github.com/vrcmarcos/flask-filtered-response
Last synced: 2 days ago
JSON representation
Add filter capability to JSON responses
- Host: GitHub
- URL: https://github.com/vrcmarcos/flask-filtered-response
- Owner: vrcmarcos
- License: mit
- Created: 2016-08-17T13:48:26.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-05-01T20:16:46.000Z (over 1 year ago)
- Last Synced: 2024-09-13T09:26:40.519Z (21 days ago)
- Language: Python
- Homepage: https://pypi.python.org/pypi/Flask-Filtered-Response
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Flask Filtered Response
Add filter capability to JSON responses
[![Build Status](https://travis-ci.org/vrcmarcos/flask-filtered-response.svg?branch=master)](https://travis-ci.org/vrcmarcos/flask-filtered-response) [![Coverage Status](https://coveralls.io/repos/github/vrcmarcos/flask-filtered-response/badge.svg?branch=master)](https://coveralls.io/github/vrcmarcos/flask-filtered-response?branch=master) [![PyPI version](https://badge.fury.io/py/Flask-Filtered-Response.svg)](https://badge.fury.io/py/Flask-Filtered-Response) [![Code Health](https://landscape.io/github/vrcmarcos/flask-filtered-response/master/landscape.svg?style=flat)](https://landscape.io/github/vrcmarcos/flask-filtered-response/master) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/vrcmarcos/flask-filtered-response/master/LICENSE)
## Instalation
```bash
pip install Flask-Filtered-Response
```## Usage
To use Flask Filtered Response, decorate your view with *@filtered* decorator:
```python
import json
from flask_filtered_response import filtered@app.route('/filtered/single_node')
@filtered
def single_node():
response_dict = {
'test_int': 123,
'test_string': 'Hey!',
}
return Response(json.dumps(response_dict))
```Using *@filtered* decorator, you will enable the ability to use the query string *fields*:
- Request:
```bash
curl -X GET http://localhost:5000/filtered/single_node?fields=test_int
```
- Response:
```json
{
"test_int": 123
}
```You can filter for multiple fields using **, (comma)**. Nested fields filtering is currently **NOT** supported.
## Changelog
#### 1.0.2:
- **@filtered**: Fixed when response data is None or Empty#### 1.0.1:
- **setup.py**: Fixed description and URL#### 1.0.0:
- **@filtered**: Created **@filtered** decorator