我想你要找的是这样的东西:
from sanic import Sanic
from sanic.response import json
app = Sanic()
@app.route("/myroute")
async def myroute(request):
param = request.raw_args.get('param', '')
signature = 'signature'
output = True if param == signature else False
return json(output)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=7777)
你只需要把你的反应写下来
response.json
.
这些端点应按预期工作:
$ curl -i http://localhost:7777/myroute
HTTP/1.1 200 OK
Connection: keep-alive
Keep-Alive: 5
Content-Length: 5
Content-Type: application/json
false
以及
$ curl -i http://localhost:7777/myroute\?param\=signature
HTTP/1.1 200 OK
Connection: keep-alive
Keep-Alive: 5
Content-Length: 4
Content-Type: application/json
true