Tag: springrest
-
How to redirect to an external URL from Spring Boot REST Controller (Post/Redirect/Get pattern)?
Let’s say you want to redirect users to an external URL when they make an API request. How to do this in Spring Boot? There are two ways you can do this. One using ResponseEntity object Two using RedirectView object. Here is how to do it with ResponseEntity object: STEP1: Create a REST Controller which…
-
How to retrieve URL and Query parameters in Spring Boot?
Let’s say you want to create a Spring Boot REST API which accepts URL and query parameters. How do you retrieve those parameters in the code ? By using @RequestParam annotation for query parameter @PathVariable annotation for URL parameter Here is an example: The above method is a GET REST service which takes in a…
-
How to pass URL and query parameters in Spring REST client?
Let’s say you are making a GET request to a third party API from your spring application. You want to pass both URL and query parameters. First, what are URL and query parameters? URL parameters: URL parameters are passed along with the URL like this: https://thirdpartyapi.com/request/1 In the above request , let’s assume the number…
-
How to log incoming requests to all REST services in Spring Boot?
(As an alternate to the below solution you can check out this post , which is easier and more straightforward) Let’s say you want to log all the requests to your REST APIs developed using Spring Boot in a centralized way. You don’t want to add logs to each and every API. How to do…
-
How to secure a REST service in Spring Boot using Basic Authentication?
Rest Services can be secured in a variety of ways: Basic Authentication , Bearer Authentication , API Keys , Open Id etc. Basic Authentication is the simplest , it uses a user name and password to secure a REST service. In this post let’s see how to protect a REST service using basic authentication in…