How to use Flask-API - 10 common examples

To help you get started, we’ve selected a few Flask-API examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CorrosiveKid / raspberrypi-gpio-api / flask-api.py View on Github external
def load_user(request):
    auth_header = request.headers.get('X-Auth')
    token_header = request.headers.get('X-Auth-Token')
    data = []

    if auth_header is not None:
        (username, password) = auth_header.split(':')
        user_entry = User.get(username)
        if user_entry is not None:
            user = User(user_entry[0], user_entry[1], user_entry[2])
            if user.password == password:
                if token_header == user.token:
                    data =  login_serializer.loads(user.token)
                    token_user = User.get(data[0])
                    #Check Password and return user or None
                    if token_user == user_entry and data[1] == password:
                        return user
    return None
github CorrosiveKid / raspberrypi-gpio-api / flask-api.py View on Github external
def load_user(request):
    auth_header = request.headers.get('X-Auth')
    token_header = request.headers.get('X-Auth-Token')
    data = []

    if auth_header is not None:
        (username, password) = auth_header.split(':')
        user_entry = User.get(username)
        if user_entry is not None:
            user = User(user_entry[0], user_entry[1], user_entry[2])
            if user.password == password:
                if token_header == user.token:
                    data =  login_serializer.loads(user.token)
                    token_user = User.get(data[0])
                    #Check Password and return user or None
                    if token_user == user_entry and data[1] == password:
                        return user
    return None
github CorrosiveKid / raspberrypi-gpio-api / flask-api.py View on Github external
def load_user(request):
    auth_header = request.headers.get('X-Auth')
    token_header = request.headers.get('X-Auth-Token')
    data = []

    if auth_header is not None:
        (username, password) = auth_header.split(':')
        user_entry = User.get(username)
        if user_entry is not None:
            user = User(user_entry[0], user_entry[1], user_entry[2])
            if user.password == password:
                if token_header == user.token:
                    data =  login_serializer.loads(user.token)
                    token_user = User.get(data[0])
                    #Check Password and return user or None
                    if token_user == user_entry and data[1] == password:
                        return user
    return None
github neo4j-examples / neo4j-movies-template / flask-api / app.py View on Github external
from flask_cors import CORS
from flask_restful import Resource, reqparse
from flask_restful_swagger_2 import Api, swagger, Schema

from neo4j.v1 import GraphDatabase, basic_auth, ResultError

from . import config


app = Flask(__name__)
app.config['SECRET_KEY'] = 'super secret guy'
api = Api(app, title='Neo4j Movie Demo API', api_version='0.0.10')
CORS(app)


driver = GraphDatabase.driver('bolt://localhost', auth=basic_auth(config.DATABASE_USERNAME, str(config.DATABASE_PASSWORD)))


def get_db():
    if not hasattr(g, 'neo4j_db'):
        g.neo4j_db = driver.session()
    return g.neo4j_db


@app.teardown_appcontext
def close_db(error):
    if hasattr(g, 'neo4j_db'):
        g.neo4j_db.close()


def set_user(sender, **extra):
    auth_header = request.headers.get('Authorization')
github neo4j-examples / neo4j-movies-template / flask-api / app.py View on Github external
'description': 'invalid / missing authentication'
            }
        }
    })
    @login_required
    def delete(self, id):
        db = get_db()
        db.run(
            '''
            MATCH (u:User {id: {user_id}})-[r:RATED]->(m:Movie {id: {movie_id}}) DELETE r
            ''', {'movie_id': id, 'user_id': g.user['id']}
        )
        return {}, 204


api.add_resource(ApiDocs, '/docs', '/docs/')
api.add_resource(GenreList, '/api/v0/genres')
api.add_resource(Movie, '/api/v0/movies/')
api.add_resource(RateMovie, '/api/v0/movies//rate')
api.add_resource(MovieList, '/api/v0/movies')
api.add_resource(MovieListByGenre, '/api/v0/movies/genre//')
api.add_resource(MovieListByDateRange, '/api/v0/movies/daterange//')
api.add_resource(MovieListByPersonActedIn, '/api/v0/movies/acted_in_by/')
api.add_resource(MovieListByWrittenBy, '/api/v0/movies/written_by/')
api.add_resource(MovieListByDirectedBy, '/api/v0/movies/directed_by/')
api.add_resource(MovieListRatedByMe, '/api/v0/movies/rated')
api.add_resource(MovieListRecommended, '/api/v0/movies/recommended')
api.add_resource(Person, '/api/v0/people/')
api.add_resource(PersonList, '/api/v0/people')
api.add_resource(PersonBacon, '/api/v0/people/bacon')
api.add_resource(Register, '/api/v0/register')
api.add_resource(Login, '/api/v0/login')
github neo4j-examples / neo4j-movies-template / flask-api / app.py View on Github external
}
        }
    })
    @login_required
    def delete(self, id):
        db = get_db()
        db.run(
            '''
            MATCH (u:User {id: {user_id}})-[r:RATED]->(m:Movie {id: {movie_id}}) DELETE r
            ''', {'movie_id': id, 'user_id': g.user['id']}
        )
        return {}, 204


api.add_resource(ApiDocs, '/docs', '/docs/')
api.add_resource(GenreList, '/api/v0/genres')
api.add_resource(Movie, '/api/v0/movies/')
api.add_resource(RateMovie, '/api/v0/movies//rate')
api.add_resource(MovieList, '/api/v0/movies')
api.add_resource(MovieListByGenre, '/api/v0/movies/genre//')
api.add_resource(MovieListByDateRange, '/api/v0/movies/daterange//')
api.add_resource(MovieListByPersonActedIn, '/api/v0/movies/acted_in_by/')
api.add_resource(MovieListByWrittenBy, '/api/v0/movies/written_by/')
api.add_resource(MovieListByDirectedBy, '/api/v0/movies/directed_by/')
api.add_resource(MovieListRatedByMe, '/api/v0/movies/rated')
api.add_resource(MovieListRecommended, '/api/v0/movies/recommended')
api.add_resource(Person, '/api/v0/people/')
api.add_resource(PersonList, '/api/v0/people')
api.add_resource(PersonBacon, '/api/v0/people/bacon')
api.add_resource(Register, '/api/v0/register')
api.add_resource(Login, '/api/v0/login')
api.add_resource(UserMe, '/api/v0/users/me')
github neo4j-examples / neo4j-movies-template / flask-api / app.py View on Github external
                'schema': GenreModel,
            }
        }
    })
    def get(self):
        db = get_db()
        result = db.run('MATCH (genre:Genre) RETURN genre')
        return [serialize_genre(record['genre']) for record in result]
github neo4j-examples / neo4j-movies-template / flask-api / app.py View on Github external
api.add_resource(GenreList, '/api/v0/genres')
api.add_resource(Movie, '/api/v0/movies/')
api.add_resource(RateMovie, '/api/v0/movies//rate')
api.add_resource(MovieList, '/api/v0/movies')
api.add_resource(MovieListByGenre, '/api/v0/movies/genre//')
api.add_resource(MovieListByDateRange, '/api/v0/movies/daterange//')
api.add_resource(MovieListByPersonActedIn, '/api/v0/movies/acted_in_by/')
api.add_resource(MovieListByWrittenBy, '/api/v0/movies/written_by/')
api.add_resource(MovieListByDirectedBy, '/api/v0/movies/directed_by/')
api.add_resource(MovieListRatedByMe, '/api/v0/movies/rated')
api.add_resource(MovieListRecommended, '/api/v0/movies/recommended')
api.add_resource(Person, '/api/v0/people/')
api.add_resource(PersonList, '/api/v0/people')
api.add_resource(PersonBacon, '/api/v0/people/bacon')
api.add_resource(Register, '/api/v0/register')
api.add_resource(Login, '/api/v0/login')
api.add_resource(UserMe, '/api/v0/users/me')
github neo4j-examples / neo4j-movies-template / flask-api / app.py View on Github external
}
    })
    @login_required
    def delete(self, id):
        db = get_db()
        db.run(
            '''
            MATCH (u:User {id: {user_id}})-[r:RATED]->(m:Movie {id: {movie_id}}) DELETE r
            ''', {'movie_id': id, 'user_id': g.user['id']}
        )
        return {}, 204


api.add_resource(ApiDocs, '/docs', '/docs/')
api.add_resource(GenreList, '/api/v0/genres')
api.add_resource(Movie, '/api/v0/movies/')
api.add_resource(RateMovie, '/api/v0/movies//rate')
api.add_resource(MovieList, '/api/v0/movies')
api.add_resource(MovieListByGenre, '/api/v0/movies/genre//')
api.add_resource(MovieListByDateRange, '/api/v0/movies/daterange//')
api.add_resource(MovieListByPersonActedIn, '/api/v0/movies/acted_in_by/')
api.add_resource(MovieListByWrittenBy, '/api/v0/movies/written_by/')
api.add_resource(MovieListByDirectedBy, '/api/v0/movies/directed_by/')
api.add_resource(MovieListRatedByMe, '/api/v0/movies/rated')
api.add_resource(MovieListRecommended, '/api/v0/movies/recommended')
api.add_resource(Person, '/api/v0/people/')
api.add_resource(PersonList, '/api/v0/people')
api.add_resource(PersonBacon, '/api/v0/people/bacon')
api.add_resource(Register, '/api/v0/register')
api.add_resource(Login, '/api/v0/login')
api.add_resource(UserMe, '/api/v0/users/me')
github neo4j-examples / neo4j-movies-template / flask-api / app.py View on Github external
    @login_required
    def delete(self, id):
        db = get_db()
        db.run(
            '''
            MATCH (u:User {id: {user_id}})-[r:RATED]->(m:Movie {id: {movie_id}}) DELETE r
            ''', {'movie_id': id, 'user_id': g.user['id']}
        )
        return {}, 204


api.add_resource(ApiDocs, '/docs', '/docs/')
api.add_resource(GenreList, '/api/v0/genres')
api.add_resource(Movie, '/api/v0/movies/')
api.add_resource(RateMovie, '/api/v0/movies//rate')
api.add_resource(MovieList, '/api/v0/movies')
api.add_resource(MovieListByGenre, '/api/v0/movies/genre//')
api.add_resource(MovieListByDateRange, '/api/v0/movies/daterange//')
api.add_resource(MovieListByPersonActedIn, '/api/v0/movies/acted_in_by/')
api.add_resource(MovieListByWrittenBy, '/api/v0/movies/written_by/')
api.add_resource(MovieListByDirectedBy, '/api/v0/movies/directed_by/')
api.add_resource(MovieListRatedByMe, '/api/v0/movies/rated')
api.add_resource(MovieListRecommended, '/api/v0/movies/recommended')
api.add_resource(Person, '/api/v0/people/')
api.add_resource(PersonList, '/api/v0/people')
api.add_resource(PersonBacon, '/api/v0/people/bacon')
api.add_resource(Register, '/api/v0/register')
api.add_resource(Login, '/api/v0/login')
api.add_resource(UserMe, '/api/v0/users/me')