This is a simple service built by FastAPI that provides the exchange rate between the two passed currencies on the passed date
You should have the following requirements installed
- Python 3
- PostgreSQL 13
- Clone the project
git clone https://github.com/Mustafa-Kamel/Currencies-exchange-rate-api - Change the active directory to the project directory
cd Currencies-exchange-rate-api - Run setup using
setup.batfor Windows users orsetup.shfor Linux users - To complete the setup and run the server run
init.batfor Windows users orinit.shfor Linux users - You will be asked to enter the credentials for the PostgreSQL server (i.e.
usernameandpassword) - Open
ratedbhandle.pyfile in any text editor and edit the database credentials to your databaseusernameandpassword - Now visit the API
To run the API you need to start the server first by navigating to the repo path from cmd/terminal and run this command uvicorn main:app --reload then you can visit this url from your browser API
You can see the api documentaion on http://localhost:8000/docs
The API receives a GET request at /rate/ and expects 3 required parameters to return the exchange rate of the first currency from_currency against the second currency to_currency on the specefied date
from_currency>[string]of 3 charactersto_currency>[string]of 3 charactersdate>[date]: The date of the exchange rate
Request Example:
/rate?from_currency=usd&to_currency=eur&date=2021-01-01
The API returns a json object consists of four parameters if both of the currencies are available
from_currency>[string]of 3 charactersto_currency>[string]of 3 charactersdate>[date]: The date of the exchange rateexchange_rate>[float]
Response Example:
{"from_currency":"CNY","to_currency":"ZAR","date":"2019-04-05","exchange_rate":2.0949}
If any of the passed currencies isn't available you will receive a 404 error message telling you that this currency isn't available
{"detail":"The passed currency NY is not available"}
And if any other error happened you will get an informatic message telling you what happened
You can run the test cases using this command pytest this will run 3 test cases:
- Successful request with HTTP response
200 - Non existent item with HTTP response
404 - Absense of one requiered parameter with HTTP response
422
This software is licensed under the GNU GPL v3.0. See the LICENSE
file in the top distribution directory for the full license text.