
demonstrates the final expense manager API in spring boot, tested via postman with register, login, and jwt authentication, and shows creating, updating, deleting expenses, with charting and pagination.
Explore how REST API enables two applications to exchange information over the internet via endpoints and standard HTTP methods, using JSON as the common data format.
Understand the three-layer architectural pattern: presentation, service, and data layers. Learn how requests travel from the client through the presentation layer to business logic, then the data layer, and back.
Download the JDK from Oracle, install it on your operating system, and verify the installation by running java -version; if issues arise, set the system environment variables and reinstall.
Choose and install your preferred development IDE for Spring Boot, such as Eclipse, IntelliJ IDEA Community or Ultimate, or Visual Studio Code, and start by downloading a database.
Install MySQL server and MySQL Workbench, set up a root user and password, test the connection, and save it to prepare the database for the expense app REST API.
Download and install the Postman REST client, a popular testing tool, and use it to test your REST API for the production-ready Spring Boot expense app.
Download and install Git from the official site, choose the appropriate installer for Windows or Mac, verify installation by running git --version, and prepare to push code to GitHub.
Compare two ways to create a spring boot project: via the SDS development aid with dependencies, and via an online starter generator that produces a zip file for IDE import.
Create a Spring Boot project with Spring Initializr, add web dependency, and import into your IDE; run the Expense Tracker API app on the embedded Tomcat.
Create a Spring Boot project in STS, configure Maven packaging and Java version, and add the Spring Web dependency to build a production-ready REST API.
Explore the Spring Boot project structure, from src/main/java with the base package and main method to resources with static assets, templates, application properties, tests, target, and Maven dependencies.
Understand Spring Boot starters and how a single starter dependency pulls in web, data, and other Maven dependencies. Build restful web services quickly with a clean, version mismatch free setup.
Explore how the Spring Boot application annotation composes configuration, enable auto-configuration, and component scan to auto-create beans and configure the web environment based on classpath dependencies.
Create the first rest endpoint for expenses with a Spring Boot rest controller, using get mapping on /expenses to return a static list of expenses via response body.
Add all dependencies to the application, including JPA, MySQL connector/J, Lombok, devtools, and Hibernate validator, to enable database access, boilerplate reduction, and automatic server restarts.
Create a database and table for an expense tracker, defining an auto-incrementing id, expense name, description, amount, category, and date, and seed with water and electricity bills.
Configure the datasource in the application properties by setting spring.datasource.url to jdbc:mysql://localhost:3306/expense_tracker, and provide spring.datasource.username and spring.datasource.password; then run the app and verify a successful database connection.
Define an expense entity mapped to the expenses table and implement a repository, service, and controller to find all expenses from the database.
Develop a spring boot api to fetch the list of expenses from the database by implementing the expense entity, repository, service, and controller, and exposing the /expenses endpoint.
Create database tables using JPA with Hibernate ddl-auto, based on entity class configuration, configure spring.jpa.hibernate.ddl-auto and spring.jpa.show-sql, and verify by inserting records into the expenses table.
Test the API in Postman and organize requests into a collection named expense manager API. Create dev and production environments, replace hosts with variables, and switch contexts to test endpoints.
Run the Spring Boot expense app from the command prompt using Maven, build with mvn clean install, and start with mvn spring-boot:run to access endpoints.
Define the api base url in the application properties, set the base path to /api/v1, and test the endpoints in postman to confirm proper routing.
Learn to pass URL parameters with path variables in Spring Boot, bind dynamic user and expense IDs to methods, and handle multiple path variables in get requests.
Implement a path variable to pass the expense id in the url, bind it as a long parameter, and return the corresponding expense in a spring boot rest controller.
Learn how to pass parameters in a URL via query strings and bind them in Spring Boot using @RequestParam for endpoints like /expenses and /users/expenses.
Learn to pass a query string parameter in the url to delete an expense via a Spring Boot rest endpoint, mapping the request and testing with Postman.
Retrieve an expense by id with a repository, handle optional results, throw a runtime exception if not found, and wire the endpoint in the expense controller.
Implement a delete by id operation for expenses in a Spring Boot REST API. Expose a delete endpoint via repository, service, and controller, and test with Postman.
Map the HTTP request body to a Java expense object using Jackson. Use @PostMapping and @RequestBody to bind JSON fields like name, description, amount, category, and date.
Define a service interface method to save expense details, implement it using the expense repository, and expose it through the expense controller to persist new expenses from a JSON payload.
Update expense details by fetching the existing expense by id, merging updated fields (name, description, category, amount, date), and persisting via the repository.
Create a rest endpoint to update expense details by id, binding the request body to an expense object, updating via the service and repository, and returning the updated expense.
Learn to store created_at and updated_at timestamps in the expense table using Hibernate creation timestamp and update timestamp annotations that auto-fill on insert and update.
Learn to apply common http status codes in a spring boot rest api, such as 200, 201, 204, 400, 403, 404, and 500, to convey request outcomes.
Configure http status codes for all rest endpoints in a spring boot expense app, using response status annotations and http status to return 200, 201, and 204.
Learn how to implement pagination and sorting in a Spring Boot REST API for the expense app using Page and Pageable, with default page size 20 and total metadata explained.
Add pagination to the expenses endpoint by updating the get all expenses method to accept page and size parameters and return a page of expenses.
Learn to add sorting to the expenses rest api in Spring Boot using the chart parameter, with optional pagination by page and size, supporting amount, name, category, or date.
Replace runtime exceptions with a custom ExpenseNotFoundException, create a dedicated exception model, and implement a global exception handler to return structured error responses in a Spring Boot REST API.
Create a custom exception in Spring Boot, define a model for exception details, and implement a global exception handler to return a structured 404 error response.
Refactor to use a single generalized resource not found exception across all resources, replacing multiple resource-specific exceptions. Apply globally to expenses, students, customers, and employees.
Handle bad request errors from type mismatches in a Spring Boot REST API by adding a global exception handler that uses MethodArgumentTypeMismatchException and returns a response with message and timestamp.
Create a custom exception to handle method argument type mismatch in Spring Boot, return a bad request with status and timestamp, and verify with Postman.
Define and handle generalized, unexpected exceptions with a global exception handler in Spring Boot, using @ExceptionHandler, returning a 500 internal server error with a timestamp and message.
Explore how a global exception handler in a Spring Boot REST API converts general exceptions into internal server errors, returns a 500 status, and logs a timestamp for debugging.
Explore how Hibernate Validator annotations enforce required fields in a Spring Boot REST API, validating expense payloads for name, amount, category, and date.
Add validation rules to the expense entity using annotations, and update the expense controller to validate the request body during binding, ensuring nulls and invalid values trigger proper exceptions.
Enable bean validation on the expense name by annotating the request with @Valid, customize messages for not null and at least three characters, and return a proper bad request response.
Customize the error response by extending a global exception handler and overriding handle method argument not valid to build a detailed response with timestamp, status, and validation messages.
Enhance the expense api with non-null and not blank validations, enforce a three-character minimum for the expense name, and apply similar rules to amount and category.
Create a rest endpoint to filter expenses by category, using a finder method like find by category with paging to return filtered results.
Create a Spring Boot rest endpoint that filters expenses by category using a repository method with pageable support and expose it via a get mapping.
Learn to filter expenses by name in a Spring Boot REST API using a containing keyword, a repository method findByNameContaining, and a paged response endpoint.
Create a rest endpoint to filter expenses by name using a like operator and pagination, wired through the expense repository, service, and controller.
Filter expenses by date with a repository method find by date between, handle optional start and end dates, and expose a paginated REST endpoint.
Create a production-ready rest endpoint in Spring Boot to filter expenses by a date range, handling null start or end dates and returning a pageable result.
Develop a new user module by building a user entity, model, repository, service, and controller, including a unique email, created and updated timestamps, and a register endpoint to persist users.
Create a new user REST endpoint in Spring Boot, including a user entity, model, repository, service, and controller. Implement password handling with @JsonIgnore and map between model and entity.
Add validations to the register api by annotating the user model with not blank, email, and size constraints, and apply @Valid in the controller to enforce rules and show errors.
Define a JPA method exists by email in user repository, create a custom item already exists exception, and globally handle it with a 409 conflict response before saving a user.
Develop a read endpoint to return only the logged-in user's information, using a service method, repository find by id, Java 8 lambda, and a get endpoint.
Create a Spring Boot REST endpoint to read user information by id, implement service and repository calls, handle not found, and return a password-free user response for testing.
Declare and implement an update method in the user service and repository, applying incoming user data with null checks for name, email, password, and age, via a put endpoint.
Implement a put /users/{id} endpoint to update user information in a spring boot app. Fetch existing user by id, merge non-null fields from the request, save, and return updated user.
Update the record to the database using the repository method, update user details, and verify changes via the api and the database.
Declare a delete method in the user service interface and implement it via the repository to delete by id. Expose a delete endpoint /users/{id} returning no content.
Create a rest endpoint in Spring Boot to delete a user in the expense app, using a delete mapping, repository call, and returning no content.
Disclaimer: This course requires you to download the Docker desktop from Docker. If you are a Udemy Business user, please check with your employer before downloading the software.
Welcome to the World's Best Online Course for learn and building Production Ready REST API for Expense Manager API. There is a lot packed into this course, Let's see what's included in this course -
NOTE: I will be updating the course when there is any changes made in the newer versions of Spring Boot.
NEW UPDATES [16/08/2024]: Added New Videos on
- Integrate Java Mapstruct Mapping Library
- Creating different mappers for copying the values from one object to another
- Reduce the boiler plate code
NEW UPDATES [27/06/2024]: Added New Videos on
- Integrating the category module with Expense module
- Refactor the expense API endpoints to accept the category
- Refactor the expense filter APIs to show the category in the response
NEW UPDATES [25/06/2024]: Added New Videos on
- Added the new category module
- Changing the existing system design
- New API endpoints for managing the category module [Create, Read, Delete]
- Best practices and tips while coding
NEW UPDATES [29/04/2024]: Added New Videos on
- Upgrading to Spring Boot v3.2.5
NEW UPDATES [31/01/2023]: Added New Videos on
- Upgrading to Spring Boot v3.0.2
- Spring Security without using WebSecurityConfigurerAdpater
NEW UPDATES [25/07/2022]: Added New Videos on
- Create REST APIs with Spring Boot and MongoDB
- Create Simple Todo REST API with all the CRUD operations using MongoRepository
- Create finder methods using MongoRepository
- Connect Spring Boot Application to MongoDB Atlas (Production database)
- Deploy the Application to Heroku
NEW UPDATES [20/05/2022]: Added New Videos on
- Dockerize the Java Program
- Dockerize the Spring Boot Application
- Dockerize the Spring Boot Application with MySQL Database
What is Spring Boot?
Spring is one of the most popular framework for building Enterprise applications
Spring Boot is a tool to create Spring based applications quickly and easily with zero configuration.
What is Spring Data JPA?
Spring Data JPA is Java Persistence API for Object Mapping, Hibernate is the default implementation for JPA.
What is Spring Security?
Spring Security is separate project, created by spring team. We can use Spring Security to secure the application.
What is JWT?
JWT is a JSON Web Token, which is used to Secure the REST APIs using token based mechanism
We will start from absolute scratch -
Understanding the REST APIs/RESTful Web Service
Understanding the basics of Spring Boot such as, Spring Boot Starters, SpringBootApplication annotation, Spring Boot project structure
You will learn the different ways of creating Spring Boot project
You will learn to create the REST end points
You will connect Spring Boot application to MySQL database
You will learn to perform the database operations using Data JPA
You will learn validating the REST APIs
You will learn handling the exceptions, custom exceptions, global exceptions and many more
You will learn adding Pagination and Sorting to REST APIs
You will learn creating REST end points for Users
You will add Spring Security to the application
You will understand the Spring Security default configuration
You will learn configuring multiple users using In-memory authentication
You will learn creating custom user details and validate user against MySQL database
You will learn the Basic Authentication
You will create REST end point for Login
You will learn reading the records only for the logged in user
You will learn Mapping two entities using OneToMany annotation
You will learn using Lombok annotations
You will learn adding JWT to the application
You will JWT token based authentication
You will learn the advance features of Postman REST client
You will learn setup the automation script inside the Postman to test APIs
You will learn basic Git commands to push the code to Github repository
You will learn deploying the application to the Production server (Heroku)
You will learn dockerize the Spring Boot Application with MySQL database