A simple Spring Boot application that provides a RESTful API to manage data operations (CRUD) for a given resource.
This project is a learning-focused implementation of a RESTful API using Spring Boot. It provides endpoints to perform CRUD (Create, Read, Update, Delete) operations on user, category, and transaction resources. The application uses PostgreSQL as the relational database and JdbcTemplate for database interactions.
This project is based on the freeCodeCamp tutorial and serves as a practical exercise in structuring and implementing a simple API.
- Spring Boot - A framework for building Java-based web applications.
- Java 11+ - The version of Java used for building the project.
- Maven - Dependency management and build tool.
- Spring Data JPA - For interacting with the database.
- PostgreSQL - Relational database for storage during development.
- Postman - API testing tool used for testing the endpoints.
Before you begin, ensure you have the following tools installed on your local machine:
- Java 11 or later: You can download it from AdoptOpenJDK.
- Maven: Follow the instructions on the Maven website for installation.
- PostgreSQL: Ensure you have PostgreSQL installed and running. You can download it from PostgreSQL Official.
- Clone the repository:
git clone https://github.com/ol1c/Spring-Boot-Java-REST-API.git
cd Spring-Boot-Java-REST-API-
Set up the PostgreSQL database:
- Make sure PostgreSQL is running on your machine.
- Create a new database, e.g.,
expensetrackerdb. - Update the database credentials in
src/main/resources/application.propertiesas follows:
spring.datasource.url=jdbc:postgresql://localhost:5432/expensetrackerdb spring.datasource.username=expensetracker spring.datasource.password=password
-
Build the project using Maven:
mvn clean install- Run the application:
mvn spring-boot:runYour app will now be running at http://localhost:8080.
You can use Postman to test the API endpoints. The following API calls are available:
The application provides API endpoints to track expenses. For example the ability to manage categories resources:
- Description: Retrieves all categories from the database.
- Response: A list of all categories in JSON format.
- Example Response:
[
{
"categoryId": 1,
"userId": 1,
"title": "Shopping",
"description": "shopping expenses",
"totalExpense": 500.0
},
{
"categoryId": 2,
"userId": 1,
"title": "Subscriptions",
"description": "all subscriptions expenses",
"totalExpense": 30.0
}
]- Description: Retrieves a single category by its ID.
- Example Request:
GET /api/categories/1 - Example Response:
{
"categoryId": 1,
"userId": 1,
"title": "Shopping",
"description": "shopping expenses",
"totalExpense": 500.0
}- Description: Creates a new category in the database.
- Example Request:
{
"title": "Shopping",
"description": "shopping expenses"
}- Example Response (created category):
{
"categoryId": 1,
"userId": 1,
"title": "Shopping",
"description": "shopping expenses",
"totalExpense": 0.0
}- Description: Updates an existing category.
- Example Request:
PUT /api/categories/1
{
"title": "Shopping",
"description": "updated description"
}- Example Response (updated category):
{
"categoryId": 1,
"userId": 1,
"title": "Shopping",
"description": "updated description",
"totalExpense": 0.0
}- Description: Deletes a category by its ID.
- Example Request:
DELETE /api/categories/1