Main goal of this project to show how you could use Finatra.
This example using Finatra for the backend and Slick for work with H2 that used as data storage. AngularJS + Bootstrap for the frontend as Single Page Application.
Finatra requires either maven or sbt to build and run your app.
You can get this example through Activator. For more information please use following url that explains how to get this template on your computer step-by-step: https://typesafe.com/activator/template/finatra-angular-example
For managing dependencies for the frontend application using Bower.
Before running application please install frontend dependencies by using following command:
$ bower install
Ti run application use following command:
$ sbt run
It will start on port 7070
, so you should see result on: http://localhost:7070
You can run tests:
$ sbt test
Application contain public API and private that requires authentication first.
You can use cURL to test application.
API response in JSON format.
Supported request types:
application/json
If you will asked for another type, server will response with code 406
and message No matching accepted Response format could be determined!
.
You can configure version of your API at resources/application.conf
.
Make sure that your requests contain correct version of API.
Default version is set to 3
.
You can get authentication token for your communication with server's private API by querying following URL:
$ curl -i -H Accept:application/json -X POST http://localhost:7070/api/v3/users/authentication
You will get response status 201
- because this method will fake user creation and provide you with auth token for private API.
You can also can check list of authenticated users by following URL (this part made only for debugging, limit is optional parameter, default 10. If limit < 0 then you will get all data):
$ curl -i -H Accept:application/json -X GET -G http://localhost:7070/api/v3/users -d limit={limit.?}
You should get response code 200
.
On following URL you can get list of available products (limit is optional parameter, default 10. If limit < 0 then you will get all data):
curl -i -H Accept:application/json -X GET -G http://localhost:7070/api/v3/products -d limit={limit.?}
You should get response code 200
.
For this part of API you need to have authentication toking provided by /api/v3/users/authentication
.
You should pass token in header with key token
.
You can get list of all products currently in your basket:
$ curl -i -H Accept:application/json -X GET -G http://localhost:7070/api/v3/cart/products -H token:{token}
- If everything is OK you should get response code
200
.
Add new product to your basket:
$ curl -i -H Accept:application/json -X PUT http://localhost:7070/api/v3/cart/products/{productId} -H token:{token}
- If everything is OK you should get response code
201
; - If you trying to add product that is already in your cart you will get response code
409
with following messageProducts is already in user's cart!
; - Parameter
productId
should be integer otherwise you will get response with code422
and messageIllegal Argument!
; - Parameter
productId
should be existing product in the market otherwise you will get response with code404
and messageProduct with provided id '{productId}' is not exist!
.
You can update quantity of product that is already in your basket:
$ curl -i -H Accept:application/json -X PUT http://localhost:7070/api/v3/cart/products/{productId}/quantity/{quantity} -H token:{token}
- If everything is OK you should get response code
204
; - Parameter
productId
should be integer otherwise you will get response with code422
and messageIllegal Argument!
; - Parameter
productId
should be existing product in the market otherwise you will get response with code404
and messageProduct with provided id '{productId}' is not exist!
; - Parameter
quantity
should be positive integer otherwise you will get response with code422
and messageIllegal Argument!
; - If you trying to update product that is not in user's shopping cart you will get response code
404
with following messageProduct should be in user's cart!
.
You can remove product from your cart using following URL:
$ curl -i -H Accept:application/json -X DELETE -G http://localhost:7070/api/v3/cart/products/{productId} -H token:{token}
- If everything is OK you should get response code
204
; - Parameter
productId
should be integer otherwise you will get response with code422
and messageIllegal Argument!
; - Parameter
productId
should be existing product in the market otherwise you will get response with code404
and messageProduct with provided id '{productId}' is not exist!
; - If you trying to remove product that is not in user's shopping cart you will get response code
404
with following messagetrying to remove product from user's shopping cart that is not there!
.
- For
Private API
if parametertoken
is missing you will get response with code401
and messageParameter 'token' is required!
; - For
Private API
if parametertoken
is wrong, there are no authorized user in the system with provided token, you will get response with code401
and messageNot Authorized!
; - For methods that are not in API, you will get response with code
404
and messageNot Found
; - For all uncovered exceptions you will get response with code
500
.
Copyright (C) 2014 Pavlo Voznenko.
Distributed under the MIT License.