-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
29 lines (24 loc) · 715 Bytes
/
main.py
File metadata and controls
29 lines (24 loc) · 715 Bytes
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
from importlib.resources import contents
from typing import Optional
from urllib import response
import uvicorn
from fastapi import FastAPI
from fastapi.responses import JSONResponse
from src.req import Data
from src.res import success, fail
from src.utils import getdaerah, getdata, baseurl
app = FastAPI()
@app.get("/api/v1/get-daerah")
def read_item():
response = getdaerah()
if response is None:
return fail(500)
return success(response)
@app.post("/api/v1/get-data")
def read_item(item: Data):
response = getdata(item.daerah)
if response is None:
return fail(400)
return success(response)
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)