Java RESTful web services that stores and returns transactions by id or type, or return the sum of a transaction and its children
The complete documentation can be found by browsing the Javadoc.
curl -i
-H "Accept: application/json"
-H "Content-Type: application/json"
-X PUT
-d "{\"amount\":1000,\"type\":\"shopping\"}"
http://localhost:8080/transactionservice/transaction/5
curl -i
-H "Accept: application/json"
-X GET
http://localhost:8080/transactionservice/transaction/1
curl -i
-H "Accept: application/json"
-X GET
http://localhost:8080/transactionservice/types/grocery
curl -i
-H "Accept: application/json"
-X GET
http://localhost:8080/transactionservice/sum/1
- Java 8
- Maven 3
- Spring 1.3.1
- Jersey 2.22.1
- Jackson 2.7.0
In this script, the choice has been made to have a fast reading of information (GET), but a longer writting (PUT).
The local database (in memory) has been optimised for a fast reading using specific indexes (parent_id and type), but they make the writting process slower. To do so, the MemoryDatabase uses three ConcurrentHashmap which performance are similar to an Hashmap and the complexity for searching, reading and insering is O(1)
which is really good.
A specific fonction had to be created to do the sum of the parent and its children. getSumRecursively()
does it recursively and its complexity is O(n)
.
- License: GNU General Public Licence (2.0)
- Author: Valentin Berclaz