Category: Spring Boot
-
Documenting your REST API’s in Spring Boot
Let’s say you have created a bunch of REST APIs. And now your client wants to use these REST APIs. They want to call a few APIs and use the response. How do you share the information with them? How many REST APIs does your application have? What are they? What is a sample request…
-
How to protect REST API using Basic Authentication?
REST APIs are one of the primary means of communication between different apps in modern web applications. Anyone can send a request to a public REST API and get a response. This poses security risk. We need only legitimate users to hit our REST APIs and get the information they need. We can do this…
-
How to connect to database from a REST API?
Web applications store data in a database. Doing so , data is stored permanently somewhere so that you can process it later. Even if your application server goes down , you still have the data in your database. Spring makes it easy to connect to any database. You require very minimal code to do this.…
-
How to create a REST API in Spring Boot?
Let’s say you want to create an ecommerce store. And you want to expose REST APIs to the end users to do CRUD(Create, Read , Update and Delete) operations on your store items. You can do this with minimal effort in Spring Boot. Let’s create the REST APIs. Creating a REST API in Spring Boot…
-
How to do server side validation in Spring Boot for REST API requests?
Let’s say you are creating a REST API to add a batsman profile to a cricket database. The API takes in batsman details like name , age ,number of matches, batting average, experience and runs . Before adding these details to our database you want to validate these details. Like name should be a valid…
-
How to connect to database using ConnectionDetails interface in Spring Boot?
Let’s say you want to connect to a database in your Spring Boot application. You first add Spring Data dependency. Then to configure the database details , you had two options: Starting Spring Boot 3.1.1 you have one more option. Using ConnectionDetails interface. Let’s see how to do that with an example. STEP 1: Add…
-
How to implement Circuit Breaker Design Pattern in Spring Boot?
Table of Contents: Problem: Fault tolerance is a major requirement for enterprise applications. If your application gets huge load , how does it behave? If something wrong happens within your application and you still want to handle it gracefully , what do you do? Fault tolerance is especially important for microservices since many microservices communicate…
-
How to implement SAGA design pattern in Spring Boot?
Contents: Problem: Microservices come with their own advantages and disadvantages. One such disadvantage is managing distributed transactions. Let’s say your transaction spans 4 different microservices. How do you ensure that your transaction either commits successfully with all the 4 tasks succeeding or fails successfully if any of the tasks is not completed ( the completed…
-
How to implement CQRS design pattern in Spring Boot?
Contents Problem: Let’s say you run a large scale ecommerce store. You have a large user base who query your system for products much more than they buy them. In other words , your system has more read requests than write requests. And so you would like to handle the high load of read requests…