Skip to content

Commit

Permalink
[Finishes #158607497] Setup flask-restful
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaOndieki committed Jun 25, 2018
1 parent da8b221 commit 7b3a45e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
15 changes: 14 additions & 1 deletion ridemyway/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from flask import Flask
from config import config
from .api.v1.routes import v1
from flask_jwt_extended import JWTManager


# An in memory database
Expand Down Expand Up @@ -40,6 +41,18 @@ def create_app(config_name):
app = Flask(__name__)
app.database = database
app.config.from_object(config[config_name])

app.config['JWT_SECRET_KEY'] = 'super-secret'
app.config['JWT_BLACKLIST_ENABLED'] = True
app.config['JWT_BLACKLIST_TOKEN_CHECKS'] = ['access', 'refresh']
app.jwt = JWTManager(app)
app.blacklist = set()

@app.jwt.token_in_blacklist_loader
def check_if_token_in_blacklist(decrypted_token):
jti = decrypted_token['jti']
return jti in app.blacklist

# Register Blueprint here
app.register_blueprint(v1, url_prefix="/api/v1")

return app
5 changes: 5 additions & 0 deletions ridemyway/api/v1/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@
v1 = Blueprint('v1', __name__)
api = Api(v1)
add = api.add_resource


# Add routes here

add(r.All, '/all') # GET
17 changes: 17 additions & 0 deletions ridemyway/resources.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
from flask_restful import Resource, reqparse
from flask_jwt_extended import (create_access_token,
create_refresh_token, jwt_required,
get_jwt_identity, get_raw_jwt)
from flask import current_app as app


class All(Resource):

def __init__(self):
pass

def get(self):
"""
Returns:
All database items
"""

return {'message': 'all'}, 201

0 comments on commit 7b3a45e

Please sign in to comment.