Hello,
In this coding exercise you I be addressing an issue/task that is central to day-to-day work: writing and maintaining microservices. This exercise aims to showcase a small microservice that fetches/calculates information about employees, creates plots and can be remotely health checked, all while running in a container.
The API provides the following basic functionalities to retrieve and serve employee data from a data source. Typically, this would be some SQL database. However, for the sake of simplicity, in this task, I am using two CSV files with fake data in the ./employees
folder.
- Calling
GET /api/employees?name=:name
returns a JSON object containing the list of all the employees who matches the:name
. :name
is an url-encoded string.- If
:name
is a single word, an entry is considered as a match if either of thefirst_name
orlast_name
matches the:name
. - When the
:name
is multiple words, an entry would be considered as a match if the last word matches thelast_name
and the rest matches thefirst_name
.
- If
- Returned objected has the following keys:
{ name, company, address, phone, email }
- The following rules apply:
name
is full name, i.e,first_name<space>last_name
.address
is constructed differently for UK and US.- For UK:
address, city, upper_case(county), postal UK
. - For US:
address, city, state zip, USA
.
- For UK:
- If both phones are available, select
phone1
for UK andphone2
for US. Also, the country code is prepended.
- Calling
GET /api/employees/
without any parameter returns a JSON array representing with following keys.{ region, count, employees }
.region
isstate
for US andcounty
for UK.count
is number of employees from thatregion
.employees
is a list containing the full name of those employees
- Calling
GET /api/wage_stats?company_name=:name&country=:country
returns an image object that shows the wage distribution of the given company.country
is an optional query parameter with the following accepted values:UK
,US
.- If country is given, use only the data from the given country, otherwise all data should be considered.
- Consider using the sum of
base_salary
andother_pay
to get wages. - The wage distribution is drawn everytime when this endpoint is called and returned as a response with
media_type
"image/png"
.
docker build -t micro_flask .
docker run -p 5000:5000 micro_flask
or
pip install -r requirements.txt
python main.py