When building HTTP facing APIs the first choice for developing those in the Spring Universe, is by using Spring MVC.
Spring MVC is Spring Frameworks’ answer for developing web applications. It is based around a central DispatcherServlet and controllers implementing the actual request handling. When a request enters the system, it is first handled by the DispatcherServlet, The DispatcherServlet will now determine which controller method is responsible for handling this request and when it find the right one, it forwards the request accordingly. Now, the controller takes over, does whatever logic it contains, returns a result which is then send back as a response. The response can either be plain JSON, XML or we use any of the server side template engines and return an HTML page.
What a controller actually does, is up to us as it is the central point we must provide for building a web application with Spring MVC.
It’s part of Spring Boot: How To Get Started and Build a Microservice and I’ll fill in the void here soon.
Getting basic auth on a application is straigth forward. Just add the Spring Security Starter to the pom or gradle.
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>
This will auto-configure Spring Security to protect your API with basic auth. It will use user as the default username and a randomly generated password on each start of the application. It prints the password in the logs.
However, we can change the username and password with proerties like:
By using Spring Cloud and NEtflix OSS, we can make our applications or microservices much more reliable.
I cover the usual steps and topics with an example in Spring Boot Intermediate Microservices.
Sometimes you still need to return XML in your Rest API for various reasons. When you build your API with Spring Boot and Spring MVC, it is a simple, easy task.
When you are starting a new Spring Boot application today, you will probably want to use Java 8. However, it still can be tricky with certain frameworks when using new features like the Date and Time API (known as JSR-310).
It is already included in Spring Boot 2. However, sometimes you might need to adjust the date handling anyways.
Uploading a file with Spring MVC is pretty easy, and it gets even easier when running in Spring Boot. However, it’s one of the tasks a developer does once in a while and therefore is pretty easy to forget. The page is a reminder for all of us.
Detecting Mobiles is straight forward with Spring Boot when you know there’s a secret module that does the heavy lifting: Spring Mobile.
In this tutorial, I show you an easy way for handling pagination when you use Spring Data and Spring MVC in your application you might not be aware of.
In this tutorial, we cover the caching feature of Sprring and how to use it in your Spring Boot application. We will use an in-memeory cache and a Redis one.
There’s an easy way to build a REST API for your Spring Data repositories instantly. It doesn’t matter if you are using JPA, MongoDB or any of the other stores available with Spring Data. Spring Data REST is the little helper. In this tutorial, we will take a closer look at how you can use it.
In your Spring MVC application, you will usually have at least one endpoint which accepts and ID as a path variable or request parameter, and often the next thing you will do is to load the model from your Spring Data repository. However, there is an easier way as you will see in a minute.