A set of django tools to help you create JSON service..
Project description
django-apiview
A set of django tools to help you create JSON service.
Install
pip install django-apiview
Installed Decorators
- @apiview
- @requires(*parameter_names)
- @choices(field, choices, allow_none=False)
- @between(field, min, max, include_min=True, include_max=True, annotation=Number, allow_none=False)
Note:
- apiview = Apiview(SimpleJsonPacker())
Usage
Note:
- You DON'T need to put django_apiview into INSTALLED_APPS.
- Apiview always set csrf_exempt=True.
- @apiview decorator must be the first decorator.
- Return raw data without serialized.
app/views.py
import time
from django_apiview.views import apiview
from django_apiview.views import requires
from django_apiview.views import choices
from django_apiview.views import between
@apiview
def ping():
return "pong"
@apiview
def timestamp():
return int(time.time())
@apiview
@requires("msg")
def echo(msg: str):
return msg
@apiview
def getBooleanResult(value : bool):
return value
@apiview
def getIntegerResult(value: int):
return value
@apiview
def getBytesResult(value: bytes):
return value
@apiview
@choices("op", ["+", "-", "*", "/"])
@between("a", 2, 10, include_min=False)
@between("b", 2, 10, include_max=False)
def calc(a: int, op: str, b: int):
if op == "+":
return a + b
if op == "-":
return a - b
if op == "*":
return a * b
if op == "/":
return a / b
Bug report
Please report any issues at https://github.com/zencore-cn/zencore-issues.
Releases
v0.3.2 2020/07/18
- Add Apiview class based implementation.
- Add setup_result_packer api.
- Rename simple_json_result_packer to simple_result_packer.
v0.3.1 2020/07/01
- Change app name from
apiview
todjango_apiview
. - Add parameter validators.
WARN
: NOT backward compatible.
v0.2.0
- Using fastutils.typingutils for annotation cast.
- Add result pack mechanism.
- Move example views from the main app to example app and the example app is not include in published package.
v0.1.3
- Add logging while getting result failed in @apiview.
- Add Map, List annotations.
v0.1.2
- Fix form process problem.
v0.1.1
- Add PAYLOAD injection, PAYLOAD field has low priority.
v0.1.0
- First release,
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
django-apiview-0.3.2.tar.gz
(5.5 kB
view details)
File details
Details for the file django-apiview-0.3.2.tar.gz
.
File metadata
- Download URL: django-apiview-0.3.2.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b79404a56be3b66e1c5018297966dff563dd9c6633174265588252f38cc9cc20 |
|
MD5 | a93ca281fe6f3e870383c03ff63174d3 |
|
BLAKE2b-256 | 9e6bc2da8cfd8381c5e5998ef2cc57695b980fa069bfb5fbe85b421da2fedbd4 |