3 Books and Courses to Learn RESTful Web Services using Spring and Java in 2025 - Best of Lot

Hello guys, if you know the Spring framework, then there is a good chance that you have heard about the classic Spring in Action book by Craig Walls. It's one of the best books to learn Spring, and many Java developers, including me, have learned Spring from that. But, even though the Spring in Action 5th Edition is one of the best books to learn Spring framework, it's just not enough to learn the intricacies of developing a modern, full-featured RESTful Web Service using Spring Framework. It does have a chapter on developing RESTful Web Services. It nicely explains concepts like @RestController, @ResponseBody, @ResponseStatus, HTTP message converters, content negotiation, but that barely touches the surface of developing a production-quality RESTFul Web Service.

Top 10 REST API, Microservices, and RESTful Web Services Book for Java Web Developers (2025)

In recent years, REST has become the standard style for developing web services, also known as RESTful Web Services. These web services take advantage of REST principles, which leverages all goodness of HTTP to provide scalable and robust web services. As a Java Web developer, it's high time that you get familiar with the REST concepts and the REST style of developing web services in Java, also known as RESTful web services, and nothing is better than to start with a good book. I often receive a request about which book should I read to learn REST? Or what are some best books to learn to develop RESTful Web services in Java, etc.? In this article, I will suggest some books which will teach you both designing a REST API and developing RESTful web services in Java.

Top 5 Books to Learn Web Service in Java in 2025 - SOAP and RESTful

If you are a Java developer and want to learn how to develop Web Services in Java, both SOAP and RESTful, but confused about where to start, then you have come to the right place. In this article, I am going to share some of the best books to learn about both SOAP and RESTful web services in Java. If you are not familiar with Web Services, it's a way to expose the services provided by your application to other developers and applications. For example, if your system offers weather information, then the user can go and check whether manually by looking at the Web GUI built using HTML, CSS, and JavaScript. Still, by exposing the same information using Web services, you allow a programmer to display as they want.

How to call REST API an send HTTP GET and POST Request using cURL command in Linux? Example Tutorial

The curl or cURL command of Linux is a compelling and versatile command which allows you to send sophisticated HTTP requests right from your Linux command line window. You can use the cURL command to test your RESTful Web Services by sending GET and POST requests, doing authentication, saving a cookie in the file, etc. The curl command is, in fact, the go-to tool for many Java and Spring developers working in web applications and consuming data from the secured RESTful Web Services. Still, you can also use it to test your simple REST Web APIs without security. I have used it many times to check if our Web service is up or not, or is there any error while accessing those services.

What is Payload in REST API? How to send Payload using HTTP Post Request and HttpClient

Hello and welcome to the blog post. In this comprehensive article we are going to take a look at an interesting topic. I’m sure you all are familiar with client-server architecture. If not let me recap it quickly for you. 

A Client is a machine (or a web-browser) that request for desired results from the  server. In other words, clients initiate requests for services or resources, while servers provide those services or resources upon request. The client-server model forms the foundation of many networked applications and systems, where clients and servers communicate and collaborate to fulfill various tasks and deliver services.

What is a Payload?

When a client sends a request to a server, the payload typically contains the data or parameters required by the server to process the request. For example, in a client-server architecture for a web application, the payload of an HTTP request sent by the client may include parameters for a form submission, JSON data for an API request, or a file to be uploaded.

On the server side, when the server sends a response back to the client, the payload contains the data or information requested by the client. This can include HTML content, JSON responses, file attachments, or any other data relevant to the specific request made by the client.

Payload in REST API

The information supplied in the body of an HTTP request is referred to as a payload in the RESTful API architecture. It represents the data that is being sent from the client to the server or the other way around. Depending on the content type supplied in the request headers, the payload may be in one of several forms, including JSON, XML, or plain text.

The payload carries the necessary data required to perform operations on the server or to retrieve specific resources. For example, when creating a new resource, the payload would typically contain the data that needs to be stored on the server. When updating an existing resource, the payload would include the modified data.

What is an HttpClient? 

HttpClient is a powerful Java package that offers quick and efficient way for submitting HTTP requests and receiving server responses. Starting with Java 11, it is a part of the Java SE standard library and offers a comprehensive API for interacting with HTTP-based services.

HttpClient's main objective is to make it easier for client applications to communicate with RESTful APIs, web services, and other HTTP-based endpoints. The low-level aspects of creating and managing connections, dealing with request and response bodies, modifying headers, controlling timeouts, and dealing with redirection are abstracted away.

You can perform various HTTP operations like GET, POST, PUT, DELETE by using HttpClient. It supports both synchronous and asynchronous request processing and offers a number of configuration options for customization.

Let’s take an example on how to send a POST request to REST API using HttpClient

import com.fasterxml.jackson.databind.ObjectMapper;

import java.net.URI;

import java.net.http.HttpClient;

import java.net.http.HttpRequest;

import java.net.http.HttpResponse;

import java.net.http.HttpHeaders;

import java.net.http.HttpResponse.BodyHandlers;


public class HttpClientExample {

    public static void main(String[] args) throws Exception {

        // Create an instance of HttpClient

        HttpClient httpClient = HttpClient.newHttpClient();


        // Define the URL of the REST API endpoint

        String url = "http://api.example.com/users";


        // Create a User object

        User user = new User("John Doe", 30);


        // Serialize the User object to JSON

        ObjectMapper objectMapper = new ObjectMapper();

        String requestBody = objectMapper.writeValueAsString(user);


        // Build the HTTP request

        HttpRequest request = HttpRequest.newBuilder()

                .uri(URI.create(url))

                .header("Content-Type", "application/json")

                .POST(HttpRequest.BodyPublishers.ofString(requestBody))

                .build();


        // Send the request and receive the response

        HttpResponse<String> response = httpClient.send(request, BodyHandlers.ofString());


        // Extract the User object from the response

        String responseBody = response.body();

        User responseUser = objectMapper.readValue(responseBody, User.class);


        // Print the response User object

        System.out.println("Response User: " + responseUser);

    }

}


class User {

    private String name;

    private int age;


    // Constructors, getters, and setters


    @Override

    public String toString() {

        return "User{" +

                "name='" + name + '\'' +

                ", age=" + age +

                '}';

    }

}


In this example, we have a User class representing the user object. We use the ObjectMapper from the Jackson library to serialize the User object to JSON format. 

We then create an HttpRequest object with the necessary details, including the URI, headers (in this case, "Content-Type" is set to "application/json"), and the request body containing the serialized User object. 

After sending the request using httpClient.send(), we receive the response as an HttpResponse object. We extract the response body as a JSON string. 

Finally, we deserialize the response JSON string back into a User object using objectMapper.readValue(). The resulting User object represents the response payload, which we can use as needed.


Sending Payload to REST API using HTTP POST Request and HttpClient in Java

import java.net.URI;

import java.net.http.HttpClient;

import java.net.http.HttpRequest;

import java.net.http.HttpResponse;

import java.net.http.HttpHeaders;

import java.net.http.HttpEntity;

import java.net.http.HttpHeaders;

import java.net.http.HttpRequest.BodyPublishers;

import java.net.http.HttpResponse.BodyHandlers;


public class HttpClientExample {

    public static void main(String[] args) throws Exception {

        HttpClient httpClient = HttpClient.newHttpClient();


        String jsonPayload = "{\"name\": \"Someone \", \"email\": \"[email protected]\"}";


        HttpRequest request = HttpRequest.newBuilder()

                .uri(URI.create("http://example.com/api/resource"))

                .header("Content-Type", "application/json")

                .POST(BodyPublishers.ofString(jsonPayload))

                .build();


        HttpResponse<String> response = httpClient.send(request, BodyHandlers.ofString());


        int statusCode = response.statusCode();

        String responseBody = response.body();


        System.out.println("Status Code: " + statusCode);

        System.out.println("Response Body: " + responseBody);

    }

}


In the example above, we create a JSON payload using a sample data object. We set the HTTP method to POST, the request URL to "http://example.com/api/resource", and the content type to "application/json". The payload is then sent in the body of the request using the BodyPublishers.ofString() method. 

Finally, we retrieve and handle the response from the server.

Remember to replace "http://example.com/api/resource" with the actual endpoint URL of the REST API you want to send the payload to, and modify the payload data according to your requirements and the API's expected format.

Let me show you how to send other types of payloads from the following example.


1) Sending a Form-UrlEncoded Payload


import java.net.URI;

import java.net.http.HttpClient;

import java.net.http.HttpRequest;

import java.net.http.HttpResponse;

import java.net.http.HttpHeaders;

import java.net.http.HttpEntity;

import java.net.http.HttpHeaders;

import java.net.http.HttpRequest.BodyPublishers;

import java.net.http.HttpResponse.BodyHandlers;

import java.net.URLEncoder;

import java.nio.charset.StandardCharsets;


public class HttpClientExample {

    public static void main(String[] args) throws Exception {

        HttpClient httpClient = HttpClient.newHttpClient();


        String payload = "name=" + URLEncoder.encode("John Doe", StandardCharsets.UTF_8)

                + "&email=" + URLEncoder.encode("[email protected]", StandardCharsets.UTF_8);


        HttpRequest request = HttpRequest.newBuilder()

                .uri(URI.create("http://example.com/api/resource"))

                .header("Content-Type", "application/x-www-form-urlencoded")

                .POST(BodyPublishers.ofString(payload))

                .build();


        HttpResponse<String> response = httpClient.send(request, BodyHandlers.ofString());


        int statusCode = response.statusCode();

        String responseBody = response.body();


        System.out.println("Status Code: " + statusCode);

        System.out.println("Response Body: " + responseBody);

    }

}


In this example, we are sending a form-urlencoded payload to the REST API endpoint "http://example.com/api/resource". The payload contains two fields, name and email, which are URL-encoded using the URLEncoder.encode() method. The Content-Type header is set to "application/x-www-form-urlencoded".



2) Sending a Plain Text Payload


import java.net.URI;

import java.net.http.HttpClient;

import java.net.http.HttpRequest;

import java.net.http.HttpResponse;

import java.net.http.HttpHeaders;

import java.net.http.HttpEntity;

import java.net.http.HttpHeaders;

import java.net.http.HttpRequest.BodyPublishers;

import java.net.http.HttpResponse.BodyHandlers;


public class HttpClientExample {

    public static void main(String[] args) throws Exception {

        HttpClient httpClient = HttpClient.newHttpClient();


        String textPayload = "This is a plain text payload.";


        HttpRequest request = HttpRequest.newBuilder()

                .uri(URI.create("http://example.com/api/resource"))

                .header("Content-Type", "text/plain")

                .POST(BodyPublishers.ofString(textPayload))

                .build();


        HttpResponse<String> response = httpClient.send(request, BodyHandlers.ofString());


        int statusCode = response.statusCode();

        String responseBody = response.body();


        System.out.println("Status Code: " + statusCode);

        System.out.println("Response Body: " + responseBody);

    }

}


In this example, we are sending a plain text payload to the REST API endpoint "http://example.com/api/resource". The payload simply contains the text "This is a plain text payload." The Content-Type header is set to "text/plain" to indicate that the payload is in plain text format.



Summary 

In summary, sending a payload to a REST API using an HTTP POST request and HttpClient in Java involves creating an HTTP request with the desired payload, specifying the necessary headers, and sending the request using the HttpClient instance. The server will process the payload and provide a response, which can be accessed and utilized accordingly.


When to use PUT or POST in a RESTful API and Web Service? Answer

Hello guys, if you are confused about whether to use PUT or POST for updating a resource using RESTful web service then you have come to the right place. In the past, I have shared the best RESTful web service books and courses and today, I am going to share some tips to choose between PUT and POST while designing your RESTful web services. Btw, you are not alone, one of the most common confusion among web developers is the choice of PUT or POST HTTP method for creating and updating a resource while developing RESTful Web Services. Since both can be used to submit data, you can use either POST or PUT to create or update a resource.
 

Top 10 RESTful Web Service Interview Questions for Java Developers

REST is an architectural style of developing web services that have become immensely popular in the last couple of years and consequently gained a lot of importance in core Java and Java EE interviews. If you are a Java web developer, then you are most likely to see a couple of questions from web services every time you go for a Java web developer interview. One of the most frequent ones is the difference between REST and SOAP web services, which I have recently answered there, but there are a lot many other good questions I have collected from friends and my readers, which I have not yet published. In this article, I am sharing those questions, mainly based on REST-style web services for your practice and preparation.

Difference between @Controller vs @RestController in Spring Framework

Hello and welcome to the blog post. If you are preparing for Java or Spring Boot interview, you may have come across this topic. In this article, we are going to have a look at the difference between @Controller and @RestController annotation. Let's understand with the help of an example.
Spring Framework is a popular open-source application framework that provides infrastructure support for developing Java applications. One of the essential components of Spring Framework is the controller, which is used to handle HTTP requests and provide responses to clients. In Spring, there are two types of controllers: @Controller and @RestController.

10 Examples of RestTemplate in Spring Framework

Hello guys, if you are wondering how to send GET and POST request to your API or Web Service from a Java based Spring Framework then you would be glad to know that You can use use RestTemplate class from Spring Framework. It's a fully functional HTTP client which is really really useful in this age of API. I have used RestTemplate to consume JSON from API before as well as sending different kind of request like POST, PUT, DELETE and PATCH to any REST API. For example, in this article, I shared how to send POST request using RestTemplate and how to set header on HTTP request using RestTemplate. Yes, RestTemplate also allow you to send headers like Authorization on Http Request. 

How to Handle REST exception in Spring Boot Application? Example Tutorial

Hello everyone, in this article we are going to take a look at how to handle REST API exceptions in Spring Boot. It is crucial to handle errors correctly in APIs by displaying meaningful messages as it helps API clients to address problems easily. What happens if we don’t handle the errors manually? By default, the spring application throws a stack trace, which is difficult to understand. Stack traces are mainly for developers hence it is useless for API clients. That's why its very important to use proper HTTP code and error messages to convey errors and exception to client and also logging so that support team can better handle them. Ideally you should tell what went wrong and how to fix it? For example, if the error is due to duplicate data then clearly say, already existed, try with a new one. Similarly, if authentication fail then clearly say authentication failed instead of throwing some other exception. 

How to set base URL for REST in Spring Boot? Example Tutorial

Hello guys, if you are wondering how to set base URL for REST API in Spring Boot then you have come to the right place. Earlier, I have shared best REST API Courses for Java developers, REST API Books,  and a complete guide to create RESTful Web service using Spring Boot, in this article, I will show you how to set a base URL in any spring boot application? If you don't know what is a base URL in a REST application or website, let me give you a brief overview first.  A base URL is the continuous element of your REST API or website's address. For example, you'll notice that the address portion http://twitter.com displays in the address bar whenever you log on to your Twitter account or visit a Twitter profile from your computer. This is the primary or base URL.

Difference between GET and POST Request in HTTP and REST APIs

HTTP Protocol supports many methods to retrieve data from the server or perform any operation on the server, like upload data, delete the file, etc. In total, the HTTP protocol supports the following methods, GET, POST, PUT, DELETE, HEAD, DELETE, OPTIONS, and TRACE, and the HTTP 1.1 reserves technique called CONNECT for future use.  GET, and POST is two of the most common HTTP methods you would hear or work on the web. Though both can be used to send and receive data from client to server, there are some crucial differences between the GET and POST in HTTP, which will help you to understand when you should use GET vs. POST while writing your client and server application.

10 Examples of New HttpClient + HttpRequest + HttpResponse In Java 11 (REST Client]

Hello guys, one of the notable addition in recent Java release is the full fledged HttpClient from Java. This is one of the class or utility which was much needed in Java. It was quite surprising that JDK doesn't have any fully functional HTTP client to connect to REST APIs in this world of API Integration. Until Java 11, Java developer rely on classes like RestTemplate and WebClient from Spring Framework to make HTTP class to REST APIs, but now you don't need to include Spring Framework in your project just for that. You can now use HttpClient class and its support classes like HttpRequest and HttpResponse to make both synchronous and asynchronous HTTP calls in Java. 

How to setup Request timeout in Spring Boot REST API? Example Tutorial

Hello guys, if you are wondering how to setup request timeout in your REST API using Spring boot then you have come to the right place. First thing first, when you make a request to another API in production, you must add timeout as there is no guarantee that you will receive response in time. Today we are going to take a look at setting up request timeout in Spring Boot Rest API. Before making it into the topic. Let’s first understand a few terms here. What is a Request timeout? A Request timeout is a deadline for services to respond to requests. It ended up returning an error with status 504 if the request fail to respond within the specified time. Request timeouts can help prevent a bad user experience, especially when a request is taking a long to respond to. There are various ways to set request timeout in Spring Boot

How to read files from the resources folder in Spring Boot? Example Tutorial

Hello everyone, welcome to the blog post. In this article, we are going to take a look at a frequently asked question in spring boot on how to read files from the resources folder. A resource is any file that contains information relevant to your project, including configuration files, picture files, data files, or other types of files. In this article, we will look at various methods and techniques that both spring boot and ordinary Java code allow us to read a file from the resources directory. Our goal is not simply to list these approaches; rather, we will describe each strategy with the help of an example so that, everyone can easily grasp the topic. Without further ado, let's get started. 

How to use @ResponseBody and @RequestBody in Spring MVC and REST? Example Tutorial

Hello guys, if you are wondering what is @RequestBody and @ResponseBody annotation in Spring MVC and Spring Boot then you have come to the right place. Earlier, I have told you about the @RestController annotation and in this article, I am going to explain to you what is RequestBody and ResponseBody annotation, how to use them, and when to use them with simple examples. While working with REST API, we may need to bind HTTP requests and response bodies with the domain object. To bind this, we use we can use the @ResponseBody and @RequestBody annotations in Spring MVC. 

Difference between SOAP and REST Style Web Service in Java

SOAP and REST are two ways to create web services in Java world, here are couple of key differences between REST and SOAP in Java