This is a POC for learning Slick and H2 DB.
Project working in progress.
The project contains two subprojects:
- api: code related for API Rest.
- common: all common classes, objects and traits.
You will need:
- Java 11
- sbt
There are three endpoints implemented:
POST /products
=> add new productPUT /products/{id}
=> update productDELETE /products/{id}
=> delete productGET /products/{id}
=> get product data of a given idGET /products
=> get the list of all products storedGET /products?vendor=name
=> retrieve the list of products filtered by vendorGET /ping
curl -X POST \
http://localhost:8080/products \
-H 'Content-Type: application/json' \
-d '{
"name": "iphone",
"vendor": "apple",
"price": 100,
"expirationDate": "2021-05-05"
}'
The field expirationDate
is optional, so the following request is also valid:
curl -X POST \
http://localhost:8080/products \
-H 'Content-Type: application/json' \
-d '{
"name": "macbook pro",
"vendor": "apple",
"price": 200
}'
curl -X PUT \
http://localhost:8080/products/123 \
-H 'Content-Type: application/json' \
-d '{
"name": "iphone",
"vendor": "apple",
"price": 100,
"expirationDate": "2021-05-05"
}'
Delete a product
:
curl -X DELETE http://localhost:8080/products/123
Get the data of a product
:
curl -X GET http://localhost:8080/products/id/123456
Get the list of all products
:
curl -X GET http://localhost:8080/products
Get the list of products
filtered by vendor
:
curl -X GET 'http://localhost:8080/products?vendor=apple'
This is just an endpoint health check.
curl -X GET http://localhost:8080/ping
From the terminal just run:
sbt api/run
From a console/terminal run:
sbt test
- Improvements in design in Database layer.
- Add business validation (Cats.Validated)
- Unit tests
- Documentation of how to replace H2 with other databases like MySql, Postgres, etc.
- OAS Specification (documentation)
- Docker