2016-10-02 03:18:41 +01:00
|
|
|
from sanic import Sanic
|
|
|
|
from sanic.response import json, text
|
2016-10-03 04:47:15 +01:00
|
|
|
from sanic.exceptions import ServerError
|
2016-10-02 03:18:41 +01:00
|
|
|
|
|
|
|
app = Sanic("test")
|
|
|
|
|
|
|
|
@app.route("/")
|
|
|
|
async def test(request):
|
|
|
|
return json({ "test": True })
|
2016-10-03 02:45:44 +01:00
|
|
|
|
2016-10-02 03:18:41 +01:00
|
|
|
@app.route("/text")
|
|
|
|
def test(request):
|
|
|
|
return text('hi')
|
|
|
|
|
2016-10-03 04:47:15 +01:00
|
|
|
@app.route("/exception")
|
|
|
|
def test(request):
|
|
|
|
raise ServerError("yep")
|
|
|
|
|
|
|
|
@app.route("/exception/async")
|
|
|
|
async def test(request):
|
|
|
|
raise ServerError("asunk")
|
|
|
|
|
2016-10-03 02:45:44 +01:00
|
|
|
@app.route("/post_json")
|
|
|
|
def test(request):
|
|
|
|
return json({ "received": True, "message": request.json })
|
|
|
|
|
|
|
|
@app.route("/query_string")
|
|
|
|
def test(request):
|
|
|
|
return json({ "parsed": True, "args": request.args, "url": request.url, "query_string": request.query_string })
|
|
|
|
|
2016-10-02 03:18:41 +01:00
|
|
|
app.run(host="0.0.0.0")
|