from sanic import Blueprint from sanic.response import json, text bp2 = Blueprint("api_2", url_prefix="/another-prefix", version="v1") bp2.__doc__ = "This is the doc string for blueprint 2." @bp2.route("/endpoint-four", methods=["GET"]) async def post(request): """Return JSON form request.""" data = request.text return json(data)
from sanic import Blueprint from sanic.response import json, text bp1 = Blueprint("api_1", url_prefix="/a-prefix", version="v1") bp1.__doc__ = "This is the doc string for blueprint 1." @bp1.route("/endpoint-one", methods=["GET"]) async def post(request): """Return text from request. INI [request] headers = {"Content-Type": "application/json","x-amz-sns-message-type": "Notification"} query = ?day=1&temp=F """ data = request.text return text(data) @bp1.route("/endpoint-two", methods=["GET"]) async def post(request): """Return JSON from GET request.""" data = request.text return json(data) @bp1.route("/endpoint-two", methods=["POST"]) async def post(request): """Return JSON from POST request.""" data = request.text