This project is a fork of the ReactJS variant of the Spring Boot PetClinic. This the primary reason for this fork is to add an OpenAPI specification for the REST API and generate the Java REST server API and TypeScript client API using the OpenAPI Generator. Several other changes were made further demonstrate best practice. The key changes are listed below:
-
Replace docker-maven-plugin with jib-maven-plugin
jib builds more efficient layered Docker images.
-
Gradle is better for Spring Boot applications.
-
Get consistent Java formatting regardless of IDE with google-java-format.
-
Project Lombok is a great way to reduce boilerplate Java code.
-
Using MapStruct to map between JPA entities and REST DTOs.
-
Clarify REST API for creating and updating entities
Avoid having IDs repeated in the URL and the body of the request.
-
Change to use SpringBoot BasicErrorController
More idiomatic for Spring Boot.
-
Ensure ownerId is correct when accessing pets
Protects against bugs and unexpected behavior.
-
Enforce minimum Java unit test coverage
To encourage tests to be written going forward.
-
OpenAPI Generator helps your code align to the specification.
-
Replace bean validation with Swagger Request Validator
Swagger Request Validator validates directly against the schema to reveal schema violations and make them easy to fix.
-
Adopting reproducible builds allows you to verify your builds and reuse Docker layers.
-
Error Prone catches bugs during the build.
-
Add Checkstyle to enforce style on Java sources
Checkstyle detects style issues and helps with conformance to Google Java Style.
-
Don't waste time on expensive JIT optimizations/profiling for short-lived code.
-
Add Nebula Gradle Lint plug-in
Gradle Lint Plugin detects issues with your Gradle configuration (e.g. duplicate classes).
-
Enable HTTP caching for GET requests.
-
Add Cache Control headers to REST API
Specify how long responses can be cached for.
-
Auto format to Google TypeScript Style
Use Google TypeScript Style to get great style without bike-shedding.
-
Upgrade react-router from 2.7 to 5.0
Make navigation simple with React Router.
-
Simplify React build config with Create React App.
-
Use generated REST client in React app
OpenAPI Generator helps your code align to the specification.
-
Change promises to async/await
Async/await allows you to write asynchronous code in simple imperative style.
-
Change React forms to use Formik
Use Formik to build forms in React in a simple idiomatic way.
-
Add code-splitting to React app
Reduce initial load times with Loadable Components.
-
Provide a consistent UI for REST API errors.
-
Use React HOC for dependency injection
Inject REST client using Higher-Order Components and React Context.
-
Snapshot Testing is a great way to increase test coverage for relatively little effort and give protection against unexpected UI changes.
-
Give little UI feedback when the server is taking a while to respond.
-
Make it easy to run the app using Docker Compose.
-
Use Codecov to track code coverage.
- Java 8
- NodeJS 10
To build run the following from the project root folder:
./build.sh
Note: Spring Boot Server App must be running before starting the client!
To start the server, launch a Terminal and run from the project's root folder:
./gradlew bootRun
When the server is running you can try to access the API for example to query all known pet types:
curl http://localhost:8080/api/pet-type
After starting the server you can run the client from the client
folder:
PORT=4444 npm start
Note: the Cross-Origin Resource Sharing configuration is set to only permit access to the REST APIs
if the client is run on port localhost:4444
(this could be changed if necessary).
To build run the following from the project root folder:
./docker-build.sh
To start the server, launch a Terminal and run from the project's root folder:
docker-compose up
Open your browser to http://localhost:4444.
John Freeman
GantSign Ltd. Company No. 06109112 (registered in England)