Skip to content

Commit e1bed92

Browse files
committed
Update sanic blueprints
1 parent 57fdee5 commit e1bed92

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

sanic-api/app/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
from .config import get_config
44
from .routes import setup_routes
55

6+
from . import blueprints
7+
68

79
def create_app(env):
810
app = Sanic(__name__)
911
config = get_config(env)
1012
app.update_config(config)
11-
12-
setup_routes(app)
13+
14+
app.blueprint(blueprints.auth.bp, url_prefix='/auth/')
15+
app.blueprint(blueprints.hello.bp, url_prefix='/api/')
1316

1417
return app

sanic-api/app/blueprints/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import auth
2+
from . import hello

sanic-api/app/blueprints/auth.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from sanic.response import json
2+
from sanic import Blueprint
3+
4+
5+
bp = Blueprint('auth')
6+
7+
8+
@bp.route('/login', methods=['POST'])
9+
async def login(request):
10+
return json({'message': 'User does not exist'})
11+

sanic-api/app/blueprints/hello.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from sanic.response import json
2+
from sanic import Blueprint
3+
4+
5+
bp = Blueprint('hello')
6+
7+
8+
@bp.route('/hello', methods=['GET'])
9+
async def hello(request):
10+
return json({'message': 'Hello world!'})

sanic-api/app/views.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,12 @@
22

33

44
async def hello_world(request):
5+
"""This is a hello world API example in Sanic
6+
7+
Args:
8+
request (_type_): _description_
9+
10+
Returns:
11+
_type_: _description_
12+
"""
513
return json({'message': 'Hello, world!'})

0 commit comments

Comments
 (0)