bottle-api
Installation
$ pip install bottle-api
Basic Usage
json_endpoint decorator will make a function to JSON WebAPI endpoint. decorated function will return bottle.HTTPResponse.
see this sample web app:
#!python
from bottleapi import WebApiError
from bottleapi.jsonapi import json_endpoint
from bottle import Bottle, request
app = Bottle()
@json_endpoint
def devide():
a = int(request.params['a'])
b = int(request.params['b'])
if b == 0:
raise WebApiError('b cannot be zero', status=400)
result = a / b
return dict(value=result)
app.route('/devide', ['GET'], devide)
if you access /device?a=1&b=1, it will return 200 OK response with body:
{"status": "ok", "result": {"value": 1}}
with Content-Type application/json
but when you access device?a=1&b=0, you will get 400 BAD REQUEST response with body:
{"status": "error", "message": "b cannot be zero", "result": null}
If you want to use JSONP, you can specify callback function name with parameter(j by default) So accessing /device?a=4&b=2&j=my_callback will result:
my_callback({"status": "ok", "result": {"value": 2}});
If you dont like parameter or result data format, You can define your own formatters(success/error). See jsonapi.py for customized formatter example.
Metadata
Release files for bottle-api 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bottle-api-0.0.4.tar.gz | 3.5 kB | Without provenance | Details for bottle-api-0.0.4.tar.gz |
Release files / bottle-api-0.0.4.tar.gz
| Download URL | bottle-api-0.0.4.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a97ef0123206e97ff8a07b080a1dfb980bbff7bb4dd6b02f292ac367b40702e4
|
|
BLAKE2b-256 checksum How to use checksums |
1e7f5cfaabc035417ceed7b720f6bef2cee8bfbc3a79181d1597458943a0670e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for bottle-api 0.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.