|
from fastapi import FastAPI, Query |
|
from forex_python.converter import CurrencyRates |
|
|
|
app = FastAPI() |
|
|
|
currency_rates = CurrencyRates() |
|
|
|
@app.get("/convert/") |
|
def convert_currency(amount: float = Query(..., description="Quantia a ser convertida"), |
|
from_currency: str = Query(..., description="Moeda de origem"), |
|
to_currency: str = Query(..., description="Moeda de destino")): |
|
""" |
|
Converte uma quantia de uma moeda para outra. |
|
""" |
|
converted_amount = currency_rates.convert(from_currency, to_currency, amount) |
|
return { |
|
"amount": amount, |
|
"from_currency": from_currency, |
|
"to_currency": to_currency, |
|
"converted_amount": converted_amount |
|
} |