from sanic import Sanic
from sanic.response import json
from sanic.websocket import WebSocketProtocol
# app = Sanic("websocket_example")
from sanic import Sanic
from sanic.views import HTTPMethodView
from sanic.response import text
app = Sanic("class_views_example")
class SimpleView(HTTPMethodView):
def get(self, request):
return text('I am get method')
# You can also use async syntax
async def post(self, request):
return text('I am post method')
def put(self, request):
return text('I am put method')
def patch(self, request):
return text('I am patch method')
def delete(self, request):
return text('I am delete method')
app.add_route(SimpleView.as_view(), '/')
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000, protocol=WebSocketProtocol)
from sanic import Sanic
from sanic.response import json
from sanic.websocket import WebSocketProtocol
# app = Sanic("websocket_example")
from sanic import Sanic
from sanic.views import HTTPMethodView
from sanic.response import text
app = Sanic("class_views_example")
class SimpleView(HTTPMethodView):
def get(self, request):
return text('I am get method')
# You can also use async syntax
async def post(self, request):
return text('I am post method')
def put(self, request):
return text('I am put method')
def patch(self, request):
return text('I am patch method')
def delete(self, request):
return text('I am delete method')
app.add_route(SimpleView.as_view(), '/')
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000, protocol=WebSocketProtocol)