A bottle plugin to json format standard and error responses. Intended for REST APIs.
Project description
=====================
bottle-api-json-formatting
=====================
A Bottle plugin which encapsulates results and errors in a json object. This
makes it much easier to build REST based api services with bottle.
Installation
===============
Install with one of the following commands:
```bash
$ pip install bottle-api-json-formatting
$ easy_install bottle-api-json-formatting
```
or download the latest version from github:
```bash
$ git clone git://github.com/bustleandflurry/bottle-api-json-formatting.git
$ cd bottle-api-json-formatting
$ python setup.py install
```
Usage
===============
```python
import bottle
import bottle_api_json_formatting
app = bottle.Bottle()
app.install(bottle_api_json_formatting.JsonFormatting())
@app.route('/')
def index():
return 'This is a test.'
@APP.route('/error')
def index():
raise Exception('This is an error.')
if __name__ == '__main__':
run(app, host='0.0.0.0', port=8080, debug=True)
```
Output
=============
Standard:
```
{
"status": "success",
"status_code": 0,
"data": "test"
}
```
Error:
```
{
"status": "error",
"status_code": 1,
"data": null,
"error": {
"status": "500 Internal Server Error",
"status_code": 500,
"message": "Internal Server Error"
}
}
```
Module Contents
=============
bottle\_api\_json\_formatting.**JsonFormatting**(*supported\_types=*['\*/\*'], *debug=False*)
*supported\_types* allows you to expressly set which Content-Types are acceptable for a json formatted response. When set any Content-Types not in the will be passed through untouched.
*debug* set to True will add the fields exception and traceback to error responses.
bottle-api-json-formatting
=====================
A Bottle plugin which encapsulates results and errors in a json object. This
makes it much easier to build REST based api services with bottle.
Installation
===============
Install with one of the following commands:
```bash
$ pip install bottle-api-json-formatting
$ easy_install bottle-api-json-formatting
```
or download the latest version from github:
```bash
$ git clone git://github.com/bustleandflurry/bottle-api-json-formatting.git
$ cd bottle-api-json-formatting
$ python setup.py install
```
Usage
===============
```python
import bottle
import bottle_api_json_formatting
app = bottle.Bottle()
app.install(bottle_api_json_formatting.JsonFormatting())
@app.route('/')
def index():
return 'This is a test.'
@APP.route('/error')
def index():
raise Exception('This is an error.')
if __name__ == '__main__':
run(app, host='0.0.0.0', port=8080, debug=True)
```
Output
=============
Standard:
```
{
"status": "success",
"status_code": 0,
"data": "test"
}
```
Error:
```
{
"status": "error",
"status_code": 1,
"data": null,
"error": {
"status": "500 Internal Server Error",
"status_code": 500,
"message": "Internal Server Error"
}
}
```
Module Contents
=============
bottle\_api\_json\_formatting.**JsonFormatting**(*supported\_types=*['\*/\*'], *debug=False*)
*supported\_types* allows you to expressly set which Content-Types are acceptable for a json formatted response. When set any Content-Types not in the will be passed through untouched.
*debug* set to True will add the fields exception and traceback to error responses.
Project details
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
Close
Hashes for bottle-api-json-formatting-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d253e323a7500b20b86e2ad4e5aff6c61c4f910f754cee274e84ca580d8387bf |
|
MD5 | 124a2d558b605acc653101452c4ea17f |
|
BLAKE2b-256 | 89f909381e84d4fa59843dcf6ff45cb00f71d5ffeb1f180fc5215ed383b94c7e |
Close
Hashes for bottle-api-json-formatting-0.1.1.linux-i686.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b83eac9208f92215884bef71257f296e22e4eca23a7e71abaef20d67a2512698 |
|
MD5 | bbb6ad26a330cb9080b2a15570a56997 |
|
BLAKE2b-256 | 8c7f51b79b3a7b62d89c0d9587c7ff5a0309fcfe261a658aa0e6b3f32af36c2e |