def create_app(): get_api_settings.cache_clear() settings = get_api_settings() settings.docs_url = "/api/docs" settings.redoc_url = "/api/redoc" settings.title = "Exponea Task Api" app = FastAPI(openapi_tags=tags_metadata, **settings.fastapi_kwargs) app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["GET"], allow_headers=["*"], ) api = Api(app, prefix="/api") api.add_resource(AllResponsesResource(), "/all", tags=["Exponea Test Server"]) api.add_resource(FirstResponseResource(), "/first", tags=["Exponea Test Server"]) api.add_resource( ThresholdResponsesResource(), "/within-timeout", tags=["Exponea Test Server"], ) api.add_resource(SmartResponseResource(), "/smart", tags=["Exponea Test Server"]) simplify_operation_ids(app) add_timing_middleware(app, record=log.info, prefix="/api") Instrumentator().instrument(app).expose(app) return app
def api(base_url): api = Api(base_url) return api # import yaml # import os # import json # basedir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # # class Data(object): # def __init__(self,file_name): # """加载数据文件,yaml——file是项目data下的文件名""" # #组装绝对路径,绑定给对象 # self.file_path = os.path.join(basedir, "data", file_name) # # # def from_yaml(self): # with open(self.file_path, encoding='utf-8') as f: # data = yaml.safe_load(f) # return data # # def from_json(self): # with open(self.file_path, encoding='utf-8') as f: # data = json.load(f) # return data # # # if __name__ == '__main__': # b = Data ("api_data.yaml") # print(b.from_yaml())
def __init__(self): with open('config.json') as f: self.config = Config(**ujson.loads(f.read())) self.api = Api(self) custom = Game(name='with a new rewrite') super().__init__(self.config.prefix, status=Status.dnd, activity=custom)
def __init__(self): """ This client assumes the developer has taken the initiative to correctly initialize the needed sessions. """ self.routes = Routes(obj=self) self.middlewares = Middlewares(obj=self) self.api = Api(obj=self) self.tables = Tables(obj=self)
def api(base_url): api = Api(base_url) return api
def authentication(): api = Api() response = api.login() assert 200 == response.status_code assert True == ("Welcome to the Secure Area." in response.text)
def api(): api = Api() return api
def setUp(self): self.api = Api() self.api.login()
def init_project(): global config with open("resources/config.json") as file: config = json.load(file) api = Api(config)
class Template: api = Api()
from base64 import b64decode, b64encode from django.db.transaction import atomic from pool.local import LocalPool from utils.api import Api from .models import Node, User pool = LocalPool('var') api = Api() @api.api def check_hash(l): return list(filter(pool.__contains__, l)) @api.api def put_block(l): for block in l: hash = block['hash'] data = b64decode(block['data']) pool[hash] = data @api.api def update_tree(add, remove): with atomic(): user = User.get() for item in remove: