As you already know, to return an error response in the Spring Boot application, we can throw a built-in ResponseStatusException or create a custom exception using the @ResponseStatus annotation and also throw it.
Returning errors to a user is crucial during web application development. When users send an incorrect request that cannot be processed or want to get information on a non-existing object, your web application should let them know what is wrong.
Data validation As you have learned, in web-based applications, a client can communicate with the server. It means that a client can request data from a server as well as send data to it.
Previously we’ve learned about a method called POST that is used for passing data to a web application server. In this section, we will explore another method for sending data called PUT.
When we want to pass information to a web application server, we usually opt for POST methods. We can actually send information of any type, even an unformatted raw string. But we tend to work with JSON, as it is one of the easiest formats to work with. JSON data can be easily converted to objects with Spring, so we can work with more complex data.
When users receive data from web applications, they may want to add new or delete the existing data. With POST requests users can add new information by sending values they want to upload.
Web-based applications communicate with a server via API — various methods that can be processed through HTTP (HyperText Transfer Protocol) requests. A controller is a part of the application that handles these API methods.
The Model-View-Controller (MVC) architecture can be used to create flexible and loosely coupled web applications. This architecture has three separate components, the model, the view, and the controller. In this topic, we will explore the functionality of each of these components and see how they can be implemented in Spring.
Spring Web MVC, commonly known as Spring MVC, is one of the modules of the core Spring framework. Spring MVC is used to create websites and RESTful services. It provides ready components that simplify and speed up the development process.
Sometimes we have to deal with situations when we need to obtain information about an authenticated user after the authentication process is completed. We might, for example, need to know the username or the roles/authorities of the user that has accessed an endpoint.