Notes:
- Python was used in this exercise instead of Java due to preference
- But I still designed code to be clean and maintanable by utilizing OOP
- And more importantly testing the code with unit tests and system tests as well as providing API documentation
To cover up for using Python instead of Java, I've added the following features:
- AWS cloud for live deployment
- Swagger for documentation and system testing
- Jenkins CI/CD for automated build and deployment
- Docker and Docker-Compose for containerization
- Curl batch scripts for automated system testing
Hopefully, there are some business lines which uses Python instead of Java for specific microservices/containers such as Data Analytics related services.
Implement API to compute a parcel cost given its weight and volume based on specific rules and conditions, including discount code from a 3rd party API.
-
Parcel class
- This computes the shipping cost given the item's weight and volume.
-
Voucher class
- This retrieves the percentage discount from a 3rd party API given a voucher code.
-
ShippingFee class
- This integrates both Parcel and Voucher classes to compute the discounted price.
-
REST API container
- This contains the API which calls the main application business logic - ShippingFee class
-
Nginx container
- Nginx was used instead of AWS ELB for identical setup in local environment to cloud environment
-
Run unittest.bat. This will run
- unittest_parcel.py - test Parcel module
- unittest_voucher.py - test Voucher module
- unittest_shipping_fee.py - test Shipping Fee module (uses Parcel and Voucher modules)
-
Go to https://app.swaggerhub.com/apis-docs/richmondu/shipping-fee_application/1.0.0
- Or go to https://petstore.swagger.io/ .
- In the textbox above, type https://myntshippingfeeapplication.s3.amazonaws.com/swagger_openapi.json .
- Click Explore button.
-
Choose Server
- local testing - http://127.0.0.1:8000
- live testing - https://richmondu.com
-
Test the API
- Click "Try it out" button
- Input weight, height, width and length
- Optional: Choose code (voucher code) for discount
- Click "Execute" button
-
curl -X GET "https://richmondu.com/api/v1/shipping/fee?code=random&weight=51&height=1&width=1&length=1" -H "accept: application/json"
-
Refer to shipping_application/_curltest for batch scripts for automated system testing
Continuous Integration and Deployment was done using Jenkins which retrieves code from my private Github repository and deploys to AWS EC2 instance