diff --git a/slow/slow.py b/slow/slow.py index 49df99d..52ce09c 100644 --- a/slow/slow.py +++ b/slow/slow.py @@ -159,3 +159,18 @@ def JSONResponse(d: dict, status=200): return HTTPResponse( json.dumps(d), status=status, content_type="text/json; charset=utf-8" ) + + +def JSONAPI(func): + def wrapper(*args, **kwargs): + result = func(*args, **kwargs) + if not isinstance(result, dict): + if ( + isinstance(result, tuple) + and len(result) == 2 + and isinstance(result[1], dict) + and isinstance(result[0], int) + ): + return JSONResponse(result[1], result[0]) + raise RuntimeError("Return value of JSONAPI route is not a dictionary") + return JSONResponse(result)