The use case realized is an in-memory cache on an application server, storing data associated with user id, in order to avoid a database dip for every request.
The code is dived in two parts a set of REST api for managing the user id and a web fronted that consume the API.
The REST api is developed using Spring boot with Tomcat as application server, Hibernate as JPA implementation and H2 as the database (it is in memory).
#### REST webservice specification:
| Method | URL | Input Body | Return Body | Description |
|---|---|---|---|---|
GET |
/users/{id} | Not required | User JSON object | Retrieve information about the user with {id}HTTP 404 code returned if the {id} is not found
|
GET |
/users | Not required | Array of user JSON objects | Retrieve all the users |
POST |
/users | User JSON object | Nothing | Create a new user |
POST |
/users/load | Not required | Nothing | Load 50 users |
PUT |
/users/{id} | User JSON object | Nothing | Update an existing user with {id}HTTP 404 code returned if the {id} is not found
|
DELETE |
/users/{id} | Not required | Nothing | Delete an existing user with {id}HTTP 404 code returned if the {id} is not found
|
The API structure is divided in three layers: DAO, Service, Controller.
- DAO: Is implemented by Spring Data. The only necessary code is defining the DAO interface
UserDAO - Service: The N Way Cache is used on this layer in order to avoid unnecessary call to database. This layer is accessible
via the
UserServicesinterface. Its implementation is done viaCachedUserServices. - Controller:
RestControlleris defining the endpoints for the REST api. It calls theUserServicefor delegating the API implementation.
User class describe the model of a user.
Application class is the entry point for Spring boot in order to launch H2 in memory database and the tomcat application
server.
NotFoundException is raised when a user is not found for a id.
The WEB frontend is an addons to the REST api in order to have an easy way to interrogate them.
The web fronted is developed using AngularJs and Bootstrap for the CSS.
It is an implementation of a basic CRUD operation around a user.