diff --git a/examples/blueprints.py b/examples/blueprints.py index 03154049..29144c4e 100644 --- a/examples/blueprints.py +++ b/examples/blueprints.py @@ -1,7 +1,5 @@ -from sanic import Sanic -from sanic import Blueprint -from sanic.response import json - +from sanic import Blueprint, Sanic +from sanic.response import file, json app = Sanic(__name__) blueprint = Blueprint('name', url_prefix='/my_blueprint') @@ -19,7 +17,12 @@ async def foo2(request): return json({'msg': 'hi from blueprint2'}) -@blueprint3.websocket('/foo') +@blueprint3.route('/foo') +async def index(request): + return await file('websocket.html') + + +@app.websocket('/feed') async def foo3(request, ws): while True: data = 'hello!' diff --git a/examples/simple_async_view.py b/examples/simple_async_view.py new file mode 100644 index 00000000..990aa21a --- /dev/null +++ b/examples/simple_async_view.py @@ -0,0 +1,42 @@ +from sanic import Sanic +from sanic.views import HTTPMethodView +from sanic.response import text + +app = Sanic('some_name') + + +class SimpleView(HTTPMethodView): + + def get(self, request): + return text('I am get method') + + 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') + + +class SimpleAsyncView(HTTPMethodView): + + async def get(self, request): + return text('I am async get method') + + async def post(self, request): + return text('I am async post method') + + async def put(self, request): + return text('I am async put method') + + +app.add_route(SimpleView.as_view(), '/') +app.add_route(SimpleAsyncView.as_view(), '/async') + +if __name__ == '__main__': + app.run(host="0.0.0.0", port=8000, debug=True)