def setup(app): from . import RestAPI_patch rest_api = RestAPI(app, default_auth=Authentication(protected_methods=[])) # register user api for api in APIRestResource.__subclasses__(): register_api(rest_api, api) api_info(app) rest_api.setup()
# aws sqs parameters sqs = boto3.client('sqs', aws_access_key_id = os.environ['AWS_ACCESS_KEY_ID'], aws_secret_access_key = os.environ['AWS_SECRET_ACCESS_KEY'], region_name = os.environ['AWS_DEFAULT_REGION']) queue_url = os.environ['QUEUE_URL'] version='1.00' start_time = datetime.now() app = Flask(__name__) app.config['JSONIFY_PRETTYPRINT_REGULAR'] = False # instantiate our api wrapper api = RestAPI(app) # register our models so they are exposed via /api/<model>/ api.register(Message) api.register(Instance) # configure the urls api.setup() @app.route('/') def test(): return "flask is running for {} seconds...".format(datetime.now() - start_time) @app.route('/add', methods=['GET'])
from flask_peewee.rest import UserAuthentication, RestAPI, RestResource from app import app from auth import auth from models import User user_auth = UserAuthentication(auth) api = RestAPI(app, default_auth=user_auth) class UserResource(RestResource): exclude = ( 'password', 'email', ) api.register(User, UserResource, auth=user_auth)
from flask_peewee.rest import RestAPI, RestResource from app import app from models import * # from auth import auth # user_auth = UserAuthentification(auth) api = RestAPI(app) # To Add for authorization: default_auth=user_auth api.register(ExploreCard)
def __init__(self): # Initialize flask self.flask = Flask('data_store') self.api = RestAPI(self.flask)
def authorize(self): """ Like I said, authorize everyone. """ return True class QuizResource(RestResource): paginate_by = False authorize_everyone = AuthorizeEveryone() api = RestAPI(app, default_auth=authorize_everyone, prefix="/%s/api" % app_config.PROJECT_SLUG) api.register(models.Quiz, QuizResource, allowed_methods=['GET', 'POST', 'PUT', 'DELETE']) api.register(models.Question, allowed_methods=['GET', 'POST', 'PUT', 'DELETE']) api.register(models.Choice, allowed_methods=['GET', 'POST', 'PUT', 'DELETE']) api.register(models.Photo, allowed_methods=['GET', 'POST', 'PUT', 'DELETE']) api.register(models.Audio, allowed_methods=['GET', 'POST', 'PUT', 'DELETE']) api.setup() @app.route('/%s/' % app_config.PROJECT_SLUG) def index():
from angular_flask import app from flask_peewee.db import Database from flask_peewee.rest import RestAPI db = Database(app) api_manager = RestAPI(app)
def create_app(): app = Flask(__name__) # Создаем экземпляр класса Flask-приложения app.url_map.strict_slashes = local_settings.TRAILING_SLASH # Указываем игнорирововать слеша в конце url app.config.from_object( local_settings) # Передаём остальные настройки в приложение return app APP = create_app() # Инициируем приложение DB = Database( APP ) # Инициируем работу с БД. Тут же создаюётся таблицы, если их нет в БД. init_models(DB) API = RestAPI(APP) # Инициируем RestAPI от peewee init_api(API) ADMIN = init_admin(APP, DB) # Инициируем Админку import ui.root # Импортируем view для главной страницы # Api на flask_restful и роуты для API from flask_restful import Api api = Api(APP) from services.product import GetProducts, AddProduct, DeleteProduct, UpdateProduct api.add_resource(GetProducts, '/product/get') api.add_resource(AddProduct, '/product/add/<int:category_id>') api.add_resource(DeleteProduct, '/product/delete/<int:product_id>')
def setup_api(auth): user_auth = UserAuthentication(auth) api = RestAPI(app, default_auth=user_auth) api.register(User, UserResource) api.setup() return api
from flask import render_template from flask import request from flask_peewee.rest import Authentication from flask_peewee.rest import RestAPI from flask_peewee.rest import RestResource from flask_peewee.utils import get_object_or_404 from app import app from models import Note from models import Task # Allow GET and POST requests without requiring authentication. auth = Authentication(protected_methods=['PUT', 'DELETE']) api = RestAPI(app, default_auth=auth) class NoteResource(RestResource): fields = ('id', 'content', 'timestamp', 'status') paginate_by = 30 #def get_urls(self): # urls = super(NoteResource, self).get_urls() # return ( # ('/search/', self.search), # ('/<pk>/details/', self.note_details), # ) + urls def get_urls(self): return (('/search/', self.search), ) + super(NoteResource, self).get_urls()
class BResourceV2(V2Resource): exclude = ("id") reverse_resources = {CModel.b: CResourceV2} class AResourceV2(V2Resource): reverse_resources = {BModel.a: BResourceV2} # rest api stuff dummy_auth = Authentication(protected_methods=[]) admin_auth = AdminAuthentication() api = RestAPI(app, default_auth=dummy_auth) api.register(Message, RestrictOwnerResource) api.register(User, UserResource, auth=admin_auth) api.register(Note, DeletableResource) api.register(AModel, AResource, auth=dummy_auth) api.register(BModel, BResource, auth=dummy_auth) api.register(CModel, CResource, auth=dummy_auth) api.register(EModel, EResource, auth=dummy_auth) api.register(FModel, FResource, auth=dummy_auth) api.register(AModel, AResourceV2, auth=dummy_auth) api.register(BModel, BResourceV2, auth=dummy_auth)
def init_app(self, app): # Инициализируем RestAPI от peewee self.extension = RestAPI(app.web_app) self.extension.default_auth = Authentication(protected_methods=[])