Posts

Showing posts with the label Spring Boot 3

Spring Boot 3 Astra DB CRUD Example

Image
In this section,  we will learn how to build REST CRUD APIs with Spring Boot , and Astra DB . Astra DB DataStax Astra DB is a cloud-native, scalable Database-as-a-Service built on Apache Cassandra . Create a Database First, Sign into the datastax at https://astra.datastax.com . Then click on the "Databases" button. You will be taken to a page like the below image, then click on the " Create Database " button. Then enter Database name , Provider , and, Region , then click on the " Create Database " button. Now, You can see "Your database is initializing..." like the below image. You will be taken to a page like the below image. Copy " Database ID " and " region name " and keep them for future purposes. Generate Application Token Mocking Then click on " Tokens " button. You will be taken to a page like the below image, Then select role, for demo purpose here we selected role " Administrator User ". Then clic

Spring RestClient Example

Image
In this section, we'll learn how to use RestClient to perform HTTP requests in a Spring Boot application. Spring Framework 6.1 introduced the RestClient API. As we all know, Spring Framework 6.1 is part of Spring Boot version 3.2. About RestClient RestClient is a synchronous client to perform HTTP requests. It is a higher-order API since it performs HTTP requests by using an HTTP client library like the JDK HttpClient, Apache HttpComponents, and others.  We can use the Spring RestClient interface  to perform HTTP requests  using a fluent API.  Fluent APIs are designed to make the code more readable and therefore easier to use. Wiring objects together using method chaining helps accomplish these readability and usability goals. Creating a RestClient  In this example we are creating RestClient using static method create(String url).  @Configuration public class RestClientConfig { @Value ( "${user.base.url}" ) String baseUrl ; @Bean RestClient restClient () {