Note: this repository is not maintained. It is only here for archival purposes. If you would like to use this microservice, please fork this repository.
Microservice created for @jay2002shah's course project in Software Engineering 1 (CS 361) at Oregon State University. This microservice uses the Open Access EchangeRate-API endpoint to generate currency exchange rate information.
These instructions will get you a copy of the microservice up and running on your local machine.
You need to have a machine with Python 3.10+ installed.
$ python --version
Python 3.10This microservice requires requests 2.28+. This can be installed globally on your machine or alternatively using pipenv.
All installation is handled using pip or pipenv. The following steps will install the microservice dependencies.
# Terminal 1
$ git clone https://github.com/4N0NYM0U5MY7H/CS361_Microservice
$ cd CS361_Microservice
# Option 1: Install depencies globally
$ python -m pip install requests
# Option 2: Install dependencies using pipenv
$ pipenv install
# Run the microservice
$ cd exchange_rate
$ python main.py# Terminal 2
$ cd CS361_Microservice
$ python example.py
# Expected output
The exchange rate from USD to EUR is 0.932527.Send a request to this microservice by updating data/requests.txt with a request string containing two ISO 4217 Three Letter Currency Codes — e.g. USD for US Dollars, EUR for Euro etc. — separated by a comma.
# Example client-side request using Python
with open("data/reqeusts.txt", w) as request:
request.write("usd,eur")Note: Here's the list of supported currency codes.
This microservice sends responses to data/response.txt with an exchange rate string — e.g. request: USD,EUR. response: 0.932527.
# Simple example client to run with the Currency Exchange Microservice
import time
import re
# <path_to_requests_file> points to the request file in the data directory
# NOTE: This example assumes the client is at the project root
path_to_requests_file = "data/requests.txt"
# <path_to_response_file> points to the request file in the data directory
# NOTE: This example assumes the client is at the project root
path_to_response_file = "data/response.txt"
# example currencies to exchange
base_currency = "usd"
target_currency = "eur"
# Send the request to the <path_to_request_file>
with open(path_to_requests_file, "w") as out_file:
out_file.write(f"{base_currency},{target_currency}")
# Poll the <path_to_response_file> until you receive a response
while True:
time.sleep(1)
# Receive the response from the <path_to_response_file>
with open(path_to_response_file, "r") as in_file:
exchange_rate = in_file.readline()
# No response received
if exchange_rate == "":
continue
# Valid reponse received
if re.search("^(0|[1-9]\d*)?(\.\d+)?(?<=\d)$", exchange_rate):
# acknowledge valid response in <path_to_response_file>
with open(path_to_response_file, "a") as out_file:
out_file.write("\nResponse Received")
break
# View the results
print(f"The exchange rate from USD to EUR is {exchange_rate}.")# Expected Output
The exchange rate from USD to EUR is 0.932527.# Unix systems
$ cd CS361_Microservice
$ mv exchange_rate data <path-to-project-root># windows
> cd CS361_Microservice
> move exchange_rate <path-to-project-root>
> move data <path-to-project-root># Run the microservice
$ cd <path-to-project-root>/exchange_rate
$ python main.py- You can now send
requests to the microservice by sending a valid request string todata/requests.txt. - You can now recieve
responses from the microservice by reading the information indata/response.txt.
Note: see Getting Started.
* Open `exchange_rate.py` in a text editor.
* Change the values of any of the `internal variables` section to suit your needs.
Note: Any changes made here will need to be reflected in your client program when communicating with the microservice.
# Run the microservice
$ cd <path-to-project-root>/CS361_Microservice/exchange_rate
$ python main.py- You can now send
requests to the microservice by sending a valid request string to:- No changes made to
exchange_rate.py:CS361_Microservice/data/requests.txt.
- Changes made to
exchange_rate.py:<your-changed-directory>/<your-changed-request-file>.
- No changes made to
- You can now recieve
responses from the microservice by reading the information from:- No changes made to
exchange_rate.py:CS361_Microservice/data/response.txt.
- Changes made to
exchange_rate.py:<your-changed-directory>/<your-changed-response-file>.
- No changes made to
Note: The microservice must be running BEFORE the client sends a request.
-
Check that you have python 3.10+ installed on your local machine
$ python --version Python 3.10.0
-
Check that you have requests 2.28+ installed on your local machine
$ python -m pip install requests
-
Check that the
exchange_rateanddatafolders are in the root of your projectproject | README.md | project files | ... |___data | | requests.txt | | response.txt | |___exchage_rate | | exchage_rate.py | | main.py | |___folder | folder files | ... | |___subfolder | subfolder files | ...- Run the microservice from the exchange_rate directory.
$ cd my/project/root $ python main.py- If you do NOT, then you will encounter issues related to the communication files.
# DO NOT do this! $ cd <project-root> $ python exchange_rate/main.py # Will cause issues with "requests.txt" and "response.txt"
- If you do NOT, then you will encounter issues related to the communication files.
- Run the microservice from the exchange_rate directory.
-
Check that your program is sending requests to
data/requests.txt -
Check that your program is receiving responses from
data/response.txtproject | ... |___data | | ... | | requests.txt | | response.txt # from project root path_to_requests_file = "data/requests.txt" path_to_response_file = "data/response.txt"
project | ... |___data | | ... | | requests.txt | | response.txt | |___folder | ... # from project folder path_to_requests_file = "../data/requests.txt" path_to_response_file = "../data/response.txt"
project | ... |___data | | ... | | requests.txt | | response.txt | |___folder | ... | |___subfolder | ... # from project subfolder path_to_requests_file = "../../data/requests.txt" path_to_response_file = "../../data/response.txt"
This project is licensed under the MIT License - see the LICENSE file for details.

