- A shopping cart application which serves the purpose of checkout in a shop.
- The application provides API for checkout in a shop.
- The API has been written in Scala using Akka.HTTP library.
- The API mainly deals with Apples and Oranges in the cart and neglects the other items.
- Apples cost 60p and oranges cost 25p.
Use either one of the following options:
- run the command
sbt run
- create a fat jar with the command
sbt assembly
and thenjava -jar target/scala-2.11/shopping_cart-assembly-1.0.0.jar
- The default hostname and port has been specified in the application.conf as
localhost
and8080
respectively. There is an provision to change these as well. Use-Dhttp.host=something_else
as an environment variable when we the jar. - The same approach goes for overriding the default port as well.
-
Swagger Docs to expose the API contracts.
-
The Swagger Json can be found in:
<shopping cart checkout server>/api-docs/swagger.json
- The Swagger UI can be found in:
<shopping cart checkout server>/swagger-ui.html
Default would be http://localhost:8080/swagger-ui.html
-
Once the application is up(either via jar or in an IDE), hit the api using the Checkout Shopping Cart URL
http://localhost:8080/shopping
. The endpoint is a POST operation. Cart - a list of strings is the the Entity that needs to be passed. -
The sample request to the shopping cart endpoint:
{
"items":[ "Apple", "Apple", "Orange", "Apple"]
}
Sample response from the shopping cart endpoint:
{
"total": "£2.05"
}
-
Once the application is up(either via jar or in an IDE), hit the api using the Checkout Shopping Cart URL
http://localhost:8080/offer
. The endpoint is a POST operation. Cart - a list of strings is the the Entity that needs to be passed. -
The sample request to the shopping cart offer endpoint:
{
"items":[ "Apple", "Apple", "Orange", "Apple"]
}
Sample response from the shopping cart offer endpoint:
{
"total": "£1.45"
}
- The shopping cart API uses Scalatest as the testing framework
- The tests can be found under the
test
directory.
- Shopping Cart service uses typesafe's logging framework with logback as a wrapper for SLF4J.
- Use
-Dlogback.configurationFile
as an environment variable to specify the logback properties(Log location, Appender config, Rolling file config)
- The shopping cart API uses Json4S for (un)marshalling purposes.
- The default Json marshaller -
akka-http-spray-json
could have boiler-plate code for different case classes and Json4S would avoid that.