Part of a tutorial on My Day To-Do Blog, this is a REST API that exposes endpoints to create and retrieve articles.
This is a simple repository that aims to highlight "how-to" achieve building a REST API with Spring Boot, with implementations of both an in-memory datastore (cache) as well as a persistent data store.
This is a simple solution where by all the incoming data is saved into an ArrayList of Article Objects. The cache (ArrayList) is an in-memory data store that exists for the app's run time. The cache is highly volatie and all data is lost on application restart.
A more versatile solution where the data is stored and retrieved from a relational database that persists data to disk. This offers the advantage of the app retaining data between application restarts. The database used is an in-memory database called H2 Database which has the option to persist the data on disk via setting it to file based storage. To know more about how to work with H2 Database in Spring, have a read of Spring Boot With H2 Database.
- Java 11
- Spring Framework (Spring Boot, JUnit)
- H2 database
- Maven
To run and modify the project start by installing the prequisite software, followed by cloning the repository and performing the seps listed.
Install the following software on your machine to later use from command line.
- Clone the repository
- Launch the terminal
- Navigate to the project directory
- Install the dependant libraries dependant and run the project,
mvn install
//build by
mvn package
//run by
mvn spring-boot:run
//run tests by
mvn test
- Once the project is running
- Launch the browser and enter
http://localhost:8080/all
The above url will show all the articles that are added on application startup to the local cache. If you want to improve the code by making changes to it, then either import it as an existing maven project in Eclipse or simply open the folder in Visual Studio Code.
To be added...
Checkout this blog for more "how-to" code samples, tutorials and just info on how to solve problems.
If you like what I am doing, you can buy me a coffee
Click on the next link for more info on the 13+ year software engineering career journey of the author.