-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
31 lines (25 loc) · 713 Bytes
/
main.py
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
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import constants
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"]
)
ESTADOS = constants.estados
DETALHES = constants.detalhes
@app.get("/")
def home():
return {"status": 200, "data": "API ESTADOS DO BRASIL ON"}
@app.get("/estados")
def estados():
return {"status": 200, "data": ESTADOS}
@app.get("/estados/detalhes/{id}")
def get_detalhes(id: int):
if id in DETALHES:
return {"status": 200, "data": DETALHES[id]}
else:
return {"status": 400, "data": "Identificador de estado inválido"}