2018-07-11 09:42:34 +01:00
|
|
|
from sanic import Sanic
|
|
|
|
from sanic.response import text
|
2021-11-23 21:00:25 +00:00
|
|
|
from sanic.views import HTTPMethodView
|
2018-07-11 09:42:34 +01:00
|
|
|
|
|
|
|
|
2021-11-23 21:00:25 +00:00
|
|
|
app = Sanic("some_name")
|
2018-07-11 09:42:34 +01:00
|
|
|
|
|
|
|
|
2021-11-23 21:00:25 +00:00
|
|
|
class SimpleView(HTTPMethodView):
|
2018-07-11 09:42:34 +01:00
|
|
|
def get(self, request):
|
2021-11-23 21:00:25 +00:00
|
|
|
return text("I am get method")
|
2018-07-11 09:42:34 +01:00
|
|
|
|
|
|
|
def post(self, request):
|
2021-11-23 21:00:25 +00:00
|
|
|
return text("I am post method")
|
2018-07-11 09:42:34 +01:00
|
|
|
|
|
|
|
def put(self, request):
|
2021-11-23 21:00:25 +00:00
|
|
|
return text("I am put method")
|
2018-07-11 09:42:34 +01:00
|
|
|
|
|
|
|
def patch(self, request):
|
2021-11-23 21:00:25 +00:00
|
|
|
return text("I am patch method")
|
2018-07-11 09:42:34 +01:00
|
|
|
|
|
|
|
def delete(self, request):
|
2021-11-23 21:00:25 +00:00
|
|
|
return text("I am delete method")
|
2018-07-11 09:42:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
class SimpleAsyncView(HTTPMethodView):
|
|
|
|
async def get(self, request):
|
2021-11-23 21:00:25 +00:00
|
|
|
return text("I am async get method")
|
2018-07-11 09:42:34 +01:00
|
|
|
|
|
|
|
async def post(self, request):
|
2021-11-23 21:00:25 +00:00
|
|
|
return text("I am async post method")
|
2018-07-11 09:42:34 +01:00
|
|
|
|
|
|
|
async def put(self, request):
|
2021-11-23 21:00:25 +00:00
|
|
|
return text("I am async put method")
|
2018-07-11 09:42:34 +01:00
|
|
|
|
|
|
|
|
2021-11-23 21:00:25 +00:00
|
|
|
app.add_route(SimpleView.as_view(), "/")
|
|
|
|
app.add_route(SimpleAsyncView.as_view(), "/async")
|
2018-07-11 09:42:34 +01:00
|
|
|
|
2021-11-23 21:00:25 +00:00
|
|
|
if __name__ == "__main__":
|
2018-07-11 09:42:34 +01:00
|
|
|
app.run(host="0.0.0.0", port=8000, debug=True)
|