Sanic framework thin wapper to write JSON API

sanic, json, api
pip install sanic-json==0.1.13


sanic json

A thin wrapper on sanic web framework to help writting JSON API.

Recommond use json-api instead. It's a abstraction library of this library.

pip3 install sanic-json


file api/

def obj_to_dict(obj):
    if not obj or isinstance(obj, (str, int, float)):
        return obj
    elif isinstance(obj, list):
        return [obj_to_dict(x) for x in obj]
    elif isinstance(obj, dict):
        return {k: obj_to_dict(v) for k, v in obj.items()}
        return {k: obj_to_dict(v) for k, v in obj.__dict__.items()}

# the wrapper will get the args and kwargs value from the `request`
async def random_pohoto(req, count=10):
    res =
    return {"data": obj_to_dict(res)}


from sanic import Sanic
from sanic_json import get_json_route
from api.random import random_pohoto

app = Sanic()
json_route = get_json_route(app)

json_route("/api/random", random_pohoto)

if __name__ == "__main__":
    import os

    debug = bool(os.getenv("DEBUG"))
    # hot reload in next release:"", port=8000, debug=debug)