How to return Different Data Formats (JSON, XML) from Spring REST API

Here I am going to show you an example on how to return different data formats from REST API using Spring Boot framework. You may have a requirement that you need to return multiple formats, such as XML, JSON, etc., from the REST response, then this example may help you. This example will return XML and JSON format depending on your HTTP settings. By default the REST will send you the JSON response. You need to set key Accept‘s value in HTTP Headers to text/xml or application/xml to get the…

Continue

Junit Testing for Multiple Files Upload Spring REST Controller

Introduction Here I am going to write Junit test case for testing multiple files upload in Spring REST Controller. I have already created how to upload multiple files using Spring REST API and I also had shown how to test it through REST client tool – Postman. In this tutorial I am going to use Junit 5, @WebMvcTest annotation to test the multiple files upload REST API. @WebMvcTest annotation can be used not only to test Spring Controllers but also Spring REST Controllers. I will build the applications using both maven…

Continue

How to upload multiple files using Spring REST API

Introduction Here in this tutorial I am going to tell you how to upload multiple files using Spring Boot REST API. I had also shown you in my another example how to upload single file using Spring Boot REST API framework. For uploading file(s) you can use any client, for example, browser or any REST client (Postman) that supports for uploading of files. Even you can write client side code using HTML, CSS jQuery/JavaScript or React JS, Angular etc. to upload multiple files.

Continue

Spring Asynchronous Request Processing via DeferredResult Class

Introduction I am going to discuss here how to perform asynchronous request processing via Spring’s DeferredResult class. A DeferredResult can be used when the application wants to produce the return value from a thread of its own choice. A DeferredResult is what is possibly not-yet-finished computation that will be available in future. Spring MVC 3.2 introduced a Servlet 3 based asynchronous request processing. Normally once request processing is finished, you leave the controller handler method, but it is not the same case with DeferredResult. Spring MVC will hold on with…

Continue

Delete Multiple Table Rows from Server using Angular 9

Introduction In this tutorial we will see how to delete multiple rows from HTML table as well as from database server at one go. We have seen tutorial how to display data from server to client side and how to select multiple rows on HTML table. We will put checkbox against each row on the table so that user will be able to select a particular row for deletion. We will also put a checkbox on the table header and selecting this checkbox all rows on the table will be…

Continue

Angular 9 Check/Uncheck Individual/All Checkbox on HTML Table Rows

Introduction Here we will create an example on how to check/uncheck individual/all checkbox on HTML table rows. We have seen how to display data from server using Angular and alternate row color using CSS. We will put checkbox against each row on the table so that user will be able to select a particular row. We will also put a checkbox on the table header and selecting this checkbox all rows on the table will be selected.

Continue

Display Data on HTML Table from Server using Angular 9 and Alternate Row Color

Introduction In this tutorial we are going to show you how to display data from server using Angular 9 and how to apply two different colors on alternate rows using css (cascading style sheet). We will use Spring Boot REST API to send data on client side and consume using client side technology Angular 9. We will use ngIf, else, ngFor directives to render data conditionally. We will show elseBlock if no record is found from the REST API. We will use index to determine odd or even column and…

Continue

Spring Data JPA IN Clause Example with WHERE Condition

Introduction In this example we will see how to work with IN clause with WHERE condition in SQL statement in Spring Data JPA. We will use MySQL server for this example. We will fetch selected rows or multiple rows selection as well as we will delete selected rows or multiple rows deletion from the table using IN operator with WHERE clause. We will use Spring transaction because we want to rollback our changes from database if any issue occurs during row deletion. The IN operator allows us to specify multiple…

Continue

Documenting REST APIs with OpenAPI 3

Introduction This tutorial will show you an example on how to document REST APIs using OpenAPI 3. When creating a REST API, good documentation is instrumental. Here we will use OpenAPI 3 in Spring application for creating documentation for REST APIs. We create and deploy REST services but we do not have an option to let others know in a single place, where REST services, having methods, request body, request params, etc., are exposed for consumption. Here we will take a look at SpringDoc — a tool that simplifies the…

Continue

REST over Https with Client certificate Authentication

Introduction The tutorial, REST over HTTPS with client certificate authentication, will show you how we can use client certificate to handshake with server along with basic authentication for consuming the service. Even you can use header authentication along with client certificate to make more secure. I will create Spring Boot application on Spring REST API and build the application using both maven and gradle build tools. I will show here both server side code and client side code using Spring Boot framework so that server expects client to establish communication…

Continue