pip install flask_limiter,flasgger,flask_restful_swagger
from flask import Flask, render_template, request, jsonify, url_for
from models.book import Book
from flask_restful import Resource, Api
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import and_, or_, desc, text, func
from flask_limiter.util import get_remote_address
from flask_limiter import Limiter
from flasgger import Swagger
from flasgger.utils import swag_from
from flask_restful_swagger import swagger
app = Flask(__name__)
app.debug = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///./db/test.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
app.config['JSON_AS_ASCII'] = False
# app.config['SQLALCHEMY_ECHO'] = True
# api = Api(app)
db = SQLAlchemy(app)
# from .views import user
api = swagger.docs(Api(app),apiVersion='0.1',api_spec_url='/docs')
# app.register_blueprint(user,url_prefix='user')
limiter = Limiter(app,key_func=get_remote_address)
limiter.init_app(app)
class Myapi(Resource):
decorators = [limiter.limit("2/day")]
@swagger.model
@swagger.operation(notes='some really good nites')
def get(self,zipcode):
return {"Response":200,
"Data":zipcode,
"msg":'success'}
api.add_resource(Myapi,'/myapi/<string:zipcode>')