-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
34 lines (20 loc) · 789 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
32
33
import uvicorn
import requests
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI(title="Crypto API", version="1.0.0", description="A simple API to get crypto data")
class CryptoData(BaseModel):
coin_id: str
@app.get("/")
def index():
return {"message": "Welcome to the Crypto API"}
@app.get("/crypto/{coin_id}")
async def crypto_info(coin_id: str):
response = requests.get(f"https://api.coingecko.com/api/v3/coins/{coin_id}")
return response.json()
@app.get("/companies/public_treasury/{coin_id}")
async def companies(coin_id: str):
response = requests.get(f"https://api.coingecko.com/api/v3/companies/public_treasury/{coin_id}")
return response.json()
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8080)