This service is tested on Mac OS X 10.7.3, installed with git version 1.7.7.5 (Apple Git-26), and Apache Maven 3.0.4
-
A system should have a stable internet connection
-
git should be installed on your system. If it's not installed, refer :
You should have a read access to clone the public repository from github.
-
Apache maven should be installed on your system. If it's not installed, refer :
-
This is optional. A client is needed to test the service. curl is simple comand line client. If it's not installed, refer:
It's a RESTful web service developed using Jersey framework. To run the project, follow the instructions
-
First clone the repository in your local system
-
Run the following command
sudo mvn clean; sudo mvn package; sudo mvn jetty:run
This step will take some time and will download all the required dependencies for the module. Once the donwloading and packaging step is done, unit test cases will run and the jetty server will be booted showing the messgae jetty server is running on port 9090. You will see the following log statement on the terminal.
INFO::Started [email protected]:9090
[INFO] Started Jetty Server
Here your are done! Your web service is up and running to server the resource request.
-
To stop the server on Linux/Mac
Ctrl+C
We can use any client for testing e.g. curl, Google chrome browser extensions viz Dev HTTP clinet, REST console, POSTMAN
I used curl for testing. Following are examples of service calls and their responses.
-
Create a transaction
curl -v -X POST -H "Content-Type:application/json" -H "Accept:application/json" -d '{ "amount": 4000, "type": "cars" }' http://localhost:9090/transactionservice/transaction
Response
HTTP/1.1 200 OK Content-Type: application/json Transfer-Encoding: chunked Server: Jetty(6.1.22)
{"amount":4000.0,"type":"cars","parent_id":0,"transaction_id":1}
-
Fetch a transaction
curl -i -X GET -H "Accept:application/json" http://localhost:9090/transactionservice/transaction/1
HTTP/1.1 200 OK Content-Type: application/json Transfer-Encoding: chunked Server: Jetty(6.1.22)
{"amount":4000.0,"type":"cars","parent_id":0,"transaction_id":1}
-
Update a transaction
curl -i -X PUT -H "Content-Type:application/json" -H "Accept:application/json" -d '{ "amount": 4000, "type": "shopping", "parent_id": 0 }' http://localhost:9090/transactionservice/transaction/1
Response
HTTP/1.1 200 OK Content-Type: application/json Transfer-Encoding: chunked Server: Jetty(6.1.22)
{"amount":4000.0,"type":"shopping","parent_id":0,"transaction_id":1}
-
Delete a transaction
curl -i -X DELETE -H "Accept:application/json" http://localhost:9090/transactionservice/transaction/1
Response
HTTP/1.1 200 OK Content-Type: application/json Transfer-Encoding: chunked Server: Jetty(6.1.22)
{"amount":4000.0,"type":"shopping","parent_id":0,"transaction_id":1}
-
Get transaction IDs, based on type.
curl -i -X GET -H "Accept:application/json" http://localhost:9090/transactionservice/types/shopping
Response
HTTP/1.1 200 OK Content-Type: application/json Transfer-Encoding: chunked Server: Jetty(6.1.22)
[4,5,6]
-
Get total amount(sum), based on transaction ID. This checks for the parentIds and calculates the sum.
curl -i -X GET -H "Accept:application/json" http://localhost:9090/transactionservice/sum/6
Response
HTTP/1.1 200 OK Content-Type: application/json Transfer-Encoding: chunked Server: Jetty(6.1.22)
{"sum":12000.0}
The HTTP 404 Not Found, 400 Bad Request, 405 Method not allowed, 500 Internal server error handling, is taken care in all the services.