XM Rest Api
This is an interview showcase work and not intended for production usage
Overview
XM Golang Exercise - v21.0.0
Config
+----------------------------------+----------+----------------+-------------------------+
| ENV | Type | Default | Description |
+----------------------------------+----------+----------------+-------------------------+
| PORT | int | 9090 | Service Port |
| METRICS_PORT | int | 7000 | Metrics Port |
| KAFKA_PRODUCER_BOOTSTRAP_SERVERS | []string | localhost:9092 | Kafka Bootstrap Servers |
| DATABASE_URL | string | root:@/test | Database Connect Url |
+----------------------------------+----------+----------------+-------------------------+
Quick start
Build the binary
go build -ldflags="-s -w" -o xm-rest-api main.go
Run the Binary
./xm-rest-api
Testing
Start Services on docker-compose, This might take 20-30min for
the first time until you pull all the required dependencies.
docker-compose up -d --build
Start the testing without building xm-rest-api image
docker-compose up -d
NOTE: if you receive following error, remove the orphan container
ERROR: for api Container "3e997fbed7c1" is unhealthy.
ERROR: Encountered errors while bringing up the project.
Stop testing environment
docker-compose down
NOTE: If you do not stop testing env properly, you'll get errors on the next start
Create Company
curl --location --request PUT 'http://localhost:9090/company' \
--header 'X-FORWARDED-FOR: 31.153.207.255' \
--header 'Content-Type: application/json' \
--data-raw '{
"name":"ABC2",
"code":"123123",
"country":"sri lanka",
"website":"",
"phone":123123
}'
Update Company
curl --location --request POST 'http://localhost:9090/company' \
--header 'X-FORWARDED-FOR: 31.153.207.255' \
--header 'Content-Type: application/json' \
--data-raw '{
"name":"ABC2",
"code":"123123",
"country":"sri lanka2",
"website":"234234",
"phone":123123
}'
Delete Company
curl --location --request DELETE 'http://localhost:9090/company?code=123123' \
--header 'X-FORWARDED-FOR: 31.153.207.255'
Get Company(s)
curl --location --request GET 'http://localhost:9090/company?code=123123&name=ABC2'
Assumptions
- Company code is unique for a company
- Only one mobile phone is available for a company
- Phone number is a number,
- Website is a optional field
Improvements
- Add support to Multiple Filters on the same type
ex:-
GET /company?code=123123&code=454545
- Data Field Validation
- Multiple Source Data write failure handling
- Topic Automatic creation if not exist
- Database data indexing