-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
64 lines (48 loc) · 1.62 KB
/
main.py
File metadata and controls
64 lines (48 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from fastapi import FastAPI
from starlette.middleware.cors import CORSMiddleware
from config.log_config import create_log
from injector import ES_HOST
import requests
import json
logger = create_log()
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
''' http://localhost:7777/docs '''
@app.get("/", tags=['API'],
status_code=200,
description="Default GET API",
summary="Return Json")
async def info():
logger.info('root')
return {"name": "python-CICD-sample-fast-api", "version": "1.0.0"}
@app.get("/es", tags=['API'],
status_code=200,
description="Default GET API",
summary="Return Json")
async def get_es_info():
logger.info(f"get_es_info hosts -> {ES_HOST}")
response = requests.get(f"{ES_HOST}/_cat/plugins?format=json")
logger.info(json.dumps(response.json(), indent=2))
return response.json()
@app.get("/test", tags=['API'],
status_code=200,
description="Default GET Param API",
summary="Return GET Param Json")
async def root_with_arg(id):
logger.info('root_with_arg - {}'.format(id))
return {"message": "Hello World [{}]".format(id)}
@app.get("/test/{id}", tags=['API'],
status_code=200,
description="Default GET with Body API",
summary="Return GET with Body Json")
async def root_with_param(id):
logger.info('root_with_arg - {}'.format(id))
return {"message": "Hello World [{}]".format(id)}
# router
# app.include_router(es_search_controller.app, tags=["Search"], )