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::
$ pip install bottle-api-json-formatting
$ easy_install bottle-api-json-formatting
or download the latest version from github::
$ git clone git://github.com/bustleandflurry/bottle-api-json-formatting.git
$ cd bottle-api-json-formatting
$ python setup.py install
Usage
===============
import bottle
import bottle-api-json-formatting
app = bottle.Bottle()
app.install(bottle_api_json_formatting.json_formatting())
@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"
}
}
Configuration
=============
bottle_api_json_formatting.json_formatting(debug=True)
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::
$ pip install bottle-api-json-formatting
$ easy_install bottle-api-json-formatting
or download the latest version from github::
$ git clone git://github.com/bustleandflurry/bottle-api-json-formatting.git
$ cd bottle-api-json-formatting
$ python setup.py install
Usage
===============
import bottle
import bottle-api-json-formatting
app = bottle.Bottle()
app.install(bottle_api_json_formatting.json_formatting())
@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"
}
}
Configuration
=============
bottle_api_json_formatting.json_formatting(debug=True)
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.0.6.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa8533ac02a3ef63a66ffbe73c89c02e4bce3cd947b593fbbaa685ade334c96e |
|
MD5 | 6594d670bbb785fa1604462d064f1221 |
|
BLAKE2b-256 | 5c08ba6d6a1cda6c6965825ee206cc385c5370d567752f1e911669f6d4438c0c |
Close
Hashes for bottle-api-json-formatting-0.0.6.linux-i686.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8369afbca3bff0ed61c56475fea8b4c664de3ae61f1feb8b7a0b03880ac77109 |
|
MD5 | 89eac1ea722a9d8e25eae272fb8c9fdc |
|
BLAKE2b-256 | 7c1c492336135f7f72a8c06e516f11ac75eda897c041d0f1f6bd9d5137eab65c |