HTTP REST API Implementation for POST amd GET using Java 8, Spring Boot, Redis / Lettuce , Mockito, Maven etc.
"{"assets":[{"id":1,"name":"Chequing","amount":2004,"currency":"USD","accountType":null},{"id":2,"name":"Savings for Taxes","amount":4000,"currency":"USD","accountType":null},{"id":3,"name":"Rainy Day Fund","amount":506,"currency":"USD","accountType":null},{"id":4,"name":"Savings for Fun","amount":4998,"currency":"USD","accountType":null},{"id":5,"name":"Savings for Travel","amount":400,"currency":"USD","accountType":null},{"id":6,"name":"Savings for Personal Development","amount":200,"currency":"USD","accountType":null},{"id":7,"name":"Investment 1","amount":5000,"currency":"USD","accountType":null},{"id":8,"name":"Investment 2","amount":60000,"currency":"USD","accountType":null},{"id":9,"name":"Investment 3","amount":30000,"currency":"USD","accountType":null},{"id":10,"name":"Investment 4","amount":50000,"currency":"USD","accountType":null},{"id":11,"name":"Investment 5","amount":24000,"currency":"USD","accountType":null},{"id":12,"name":"Primary Home","amount":455000,"currency":"USD","accountType":null},{"id":13,"name":"Second Home","amount":1564321,"currency":"USD","accountType":null}],"liabilities":[{"id":14,"name":"Credit Card 1","amount":4342,"currency":"CAD","accountType":null},{"id":15,"name":"Credit Card 2","amount":322,"currency":"CAD","accountType":null},{"id":16,"name":"Mortgage 1","amount":250999,"currency":"CAD","accountType":null},{"id":17,"name":"Mortgage 2","amount":632634,"currency":"CAD","accountType":null},{"id":18,"name":"Line of Credit","amount":10000,"currency":"CAD","accountType":null},{"id":19,"name":"Investment Loan","amount":10000,"currency":"CAD","accountType":null}]}"
"{"id":7,"totalAssets":2200429,"totalLiabilities":908297,"netWorth":1292132}"
http://localhost:8080/portfolios/
[ "{"id":1,"totalAssets":2200427,"totalLiabilities":908297,"netWorth":1292130}", "{"id":2,"totalAssets":2200427,"totalLiabilities":908297,"netWorth":1292130}", "{"id":3,"totalAssets":2200428,"totalLiabilities":908297,"netWorth":1292131}", "{"id":5,"totalAssets":2200431,"totalLiabilities":908297,"netWorth":1292134}", "{"id":7,"totalAssets":2200429,"totalLiabilities":908297,"netWorth":1292132}", "{"id":4,"totalAssets":2200430,"totalLiabilities":908297,"netWorth":1292133}", "{"id":6,"totalAssets":2200430,"totalLiabilities":908297,"netWorth":1292133}" ]
http://localhost:8080/portfolios/7
Details response contains both POST Request and Response (as above)
This is a simple demonstration of calculating net worth based on assets and liabilities. The first request will be a list of assets and libilities based on which net worth is calculated and response is provided. Each response will have an unique ID and both request and respose are stored in a persistent system.
This simple implementation demonstrates a production ready service side software of HTTP REST API implementation.
- Spring Boot is used to create HTTP End Point through the Controller implementation [ PortfolioTrackerServices/src/main/java/com/portfolio/tracker/NetWorthTrackerController.java ]
- Service and Database are separate components injected to the Controller through @Autowired Dependency Injection
- Redis is currently used as a persistent storage to store [ PortfolioTrackerServices/src/main/java/com/portfolio/tracker/PortfolioDatabaseRedis.java ]
- Redis has two HashMap to store Request and Response as JSON string based on the ID created for each request
- JUnit and Mockito is use for Unit Testing [ PortfolioTrackerServices/src/test/java/com/portfolio/tracker/NetWorthTrackerControllerTest.java ]
- Maven is used for software project management and build tool
Client side app is developed using Angular JS 2. [Will be available soon]