Category: Spring Boot
-
Defining projections with Jackson views, REST and Spring Boot
Sometimes it makes sense to reuse DTOs when building REST interfaces. It is convenient as you do not need to re-implement them for every interface and it makes your API consistent as changes in the DTO will be reflected everywhere. However, you might need to send different subsets of data at different interfaces. For example,…
-
How to configure fiegn clients to perform HTTP requests in Spring
In our previous tutorial, we discussed how to configure and enable OpenFeign and Feign clients in a Spring boot application. In this tutorial, we will dig deeper into Feign clients and discuss how to create and configure Feign clients to call external services using the HTTP GET, PUT. POST and DELETE functions. We will also…
-
How to configure OpenFeign with Spring boot
In this tutorial, we will discuss how to configure OpenFeign and a Feign client in a Spring boot application in order to make a REST call to a REST API service in another application. The goal of this tutorial is to get you started with OpenFeign basics in Spring boot and to demonstrate how you…
-
How to configure path variables in Spring controllers
Path variables are an essential component which we use when interacting with REST APIs. In this tutorial, we will discuss what path variables are (not to be confused with query parameters) and how to use and configure them in Spring controllers. If you are just starting out with building REST APIs in Spring or Spring…
-
How to configure query parameters in Spring Controllers
In this post, we will discuss what query parameters are and how to configure them in a Spring controller using the @RequestParam annotation. We will also discuss how to set your query parameters as optional, how to configure multiple query parameters and more. Before we start, I highly recommend that you check out our introductory…
-
How to use Java Bean Validation in Spring Boot
Java bean validation, AKA JSR-303 is a Java standard which is used to perform validation on items inside a Java application. Validation is performed by applying “constraints” on data items. As long as the data satisfies these constraints, it will be considered valid. Such constraints can be a specific numerical value range, being null or…
-
Error handling in REST and Spring Boot
In our previous tutorials, we discussed how build a CRUD REST API in a Spring Boot environment. However, we have not yet discussed how to handle common errors that can occur, such as when the user tries to fetch a non-existing item. In this tutorial, we will discuss some solutions and strategies for handling errors…
-
Using PUT vs PATCH when building a REST API in Spring
In our previous post “how to create a CRUD REST API in Spring Boot”, we discussed how to create a basic REST interface in Spring boot using the different HTTP verb mapping annotations @GetMapping, @DeleteMapping, @PutMapping and @PostMapping. These mappings correspond to the HTTP methods GET, DELETE, PUT and POST respectively. However, we have not…
-
How to validate REST calls in Spring Boot
In our previous post, we discussed how to get started with REST in Spring boot, and how to get a REST endpoint up and running. However, callers of the endpoint were able to send any data to our server, and this data would be accepted and saved by our server without any sort of checks…
-
How to create a CRUD REST API in Spring Boot
REST APIs are a very important layer in many Spring applications. Specially if you need to provide interfaces for other services in your ecosystem such as front-end applications or to external systems, such as customer systems. In this post, we will discuss how to start building your REST API using Spring Boot in order to…