This project is created with Java Language and Spring Boot Framework and hosted on AWS(With API Gateway, Lambda(Serverless) and Cloudfront).
- GET - /ping - Returns "Hello, World!" if the application is successfully running
- GET - /api/v1/next-tracking-number - Generates and returns a tracking number and created timestamp. The tracking number is generated based on the following method:
a. Current Time in ms + (Random Number * 1000).
b. Converting the value from Step a to Base 36, this is done to represent it in a compact alphanumeric format, reducing the size of the ID.
c. If the value from Step b has a length of more than 16 characters, it is truncated to 16 characters length.
d. To ensure uniqueness, Origin Country ID + Destination Country ID + value from Step c + Weight from API Request Parameters are added.
e. Finally, all characters are converted to uppercase, the length is truncated to 16 characters, and any character other than A-Z and 0-9 is replaced with 'X'.
- Currently the configuration is set to run on port 9091, please change the port based on your usage(file location - src\main\resources\application.properties).
- The Logging level is set to WARN, please change it per your usage.
The project folder also includes a template.yml file. You can use this SAM file to deploy the project to AWS Lambda and Amazon API Gateway or test in local with the SAM CLI.
- Clone the Git Repository
- Run the following command, if you are using Maven, this will get you the zip file that will be help you deploy and run on AWS Services(this is through SAM Deployment)
mvn spring-boot::run
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13.141 s
[INFO] Finished at: 2025-01-09T19:22:33+05:30
[INFO] ------------------------------------------------------------------------
- Ping API
$ curl --location 'https://pwcwxkognl.execute-api.eu-north-1.amazonaws.com/dev/ping'
{
"pong": "Hello, World!"
}
- Tracking Number Generator API
$ curl --location 'https://pwcwxkognl.execute-api.eu-north-1.amazonaws.com/dev/api/v1/next-tracking-number?origin_country_id=MY&destination_country_id=ID&weight=1.234&created_at=2018-11-20T19%3A29%3A32%2B08%3A00&customer_id=de619854-b59b-425e-9db4-943979e1bd49&customer_name=RedBox%20Logistics&customer_slug=redbox-logistics'
{
"tracking_number": "MYIDM5PE3M4C1X23",
"created_at": "2025-01-09T13:54:19.150976644Z"
}
Validation rules for Tracking Number Generator API (for the purpose of this Code Test all fields are assumed mandatory)
- origin_country_id - is mandatory and has to be 2 characters length with Uppercase alphabet.
- destination_country_id - is mandatory and has to be 2 characters length with Uppercase alphabet.
- weight - is mandatory and has to be greater than 0(zero).
- created_at - is mandatory and has to be in RFC 3339 format.
- customer_name - is mandatory and cannot be blank.
- customer_slug - is mandatory and checks for slug-case/kebab-case.
- Ping API - https://pwcwxkognl.execute-api.eu-north-1.amazonaws.com/dev/ping
- Tracking Number Generator API - https://pwcwxkognl.execute-api.eu-north-1.amazonaws.com/dev/api/v1/next-tracking-number?origin_country_id=<origin_country_id>&destination_country_id=<destination_country_id>&weight=&created_at=<created_at>&customer_id=<customer_id>&customer_name=<customer_name>&customer_slug=<customer_slug> (an example is mentioned in the curl command above)
We have created two classes to write and run Unit Test Cases -
- StreamLambdaHandlerTest - Has test cases to check the serverless connection with AWS Lambda..
- TrackingNumGenControllerTest - Has test cases to check the business logic, request and response, if they are working as expected.
Has been done through Postman.
- We can run a performance and load test on the API to check for lags and update the system configurations to improve the performance.
- Run multiple test cases with different ramp up periods with a tool like JMeter.