Joke spawn from Python Discord that was expanded to be used to show off why Micro Services are done and to learn Kubernetes
Micro Micro Service is currently built off 3 primary services with 3 supporting backend services These services are math/date/name
The application is powered by FastAPI. All Python files for running FastAPI are located in /app. There is 6 primary services in root of app along with 6 routers located in /app/routers with _router added to end of FastAPI they support.
Class Modules, only currently used to support database operations for name service are located in /app/modules
Easy way to get it running is docker-compose, if you have Powershell and Docker installed, execute Powershell Script Run-DockerCompose -Action Up
Using CLI would be "docker compose --project-name micro up -d --build"
There is Nginx container that will expose itself on port 9000 and provide proxying for all services. However, docker compose will expose each service on different port for direct testing and reading of documentation. The port binds are as follows:
Service | Port | Documentation |
---|---|---|
calc-main | 9001 | http://127.0.0.1:9001/docs |
calc-micro | 9002 | http://127.0.0.1:9002/docs |
date-main | 9003 | http://127.0.0.1:9003/docs |
date-micro | 9004 | http://127.0.0.1:9004/docs |
name-main | 9005 | http://127.0.0.1:9005/docs |
name-micro | 9006 | http://127.0.0.1:9006/docs |
There is Powershell Pester Tests and container to support running those tests. It will by default be started during docker compose where it will test all the services. You can also manually execute the tests by running Powershell script Run-TestContainer.ps1 and it will connect using docker interactive mode and execute the Powershell Tests.
Powershell files can be found in pstests and Invoke-Tests.ps1 contains actual tests.
Primary Math end point by default is at /math/calc
It takes a POST with following JSON body:
{
"op": operator (supported is add/subtract/multiply/divide/expo/remainder),
"number1": 1,
"number2": 1
}
Supporting Micro Services is at /math/api/ with following endpoints all using HTTP get,
Service | Endpoint |
---|---|
add | /math/api/add?number1=&number2= |
subtract | /math/api/subtract?number1=&number2= |
multiply | /math/api/multiply?number1=&number2= |
divide | /math/api/divide?number1=&number2= |
expo | /math/api/expo?number1=&number2= |
remainder | /math/api/remainder?number1=&number2= |
Primary Date endpoint by default is at /date/today with all returns in UTC.
It takes a POST with following JSON body:
{
"format": (Supported is american, european, iso8601)
}
Supporting Micro Services is at /date/api with following endpoints all support HTTP GET:
Service | Endpoint |
---|---|
day | /date/api/today_day |
month | /date/api/today_month |
year | /date/api/today_year |
Primary Name Endpoint is at /name/user with 3 METHODs supported of GET/POST/DELETE.
GET/DELETE endpoint is /name/user?userid=(UserID) which will get user data or delete it.
POST to endpoint will return a new user with following body:
{
"userid": (UUID),
"first_name": (First Name),
"surname": (Surname),
"email": ([email protected])
}
All Names are generated by service for ease to use and were taken from CSV files with popular baby names and surnames provided United States Census Bureau. If you wish to replace, you can by replacing CSV files in /app/names
Email domain is controlled by environment variable "email_domain" on name_micro container if you wish to set it. By default, example.com is used keeping with RFC 2606.
Micro Services are at /name/api/ supporting various methods. For this Micro Services, GET will always get data, POST will always create data, DELETE will always remove
Service | Endpoint | Supported Methods |
---|---|---|
first | /name/api/first | GET, POST, DELETE |
surname | /name/api/surname | GET, POST, DELETE |
/name/api/email | GET, POST, DELETE | |
alluserids | /name/api/alluserids | GET |
userid | /name/api/userid | POST, DELETE |