Spring Boot: RestTemplate
When you need to access other APIs from the backend of your Spring Boot Application
Suppose you are in the backend code of your Spring Boot application and you want to access some other API, e.g. the https://developer.ucsb.edu API.
What code can you use?
Here is a tutorial on the REST client built into Spring Boot called RestTemplate
:
- https://howtodoinjava.com/spring-boot2/resttemplate/spring-restful-client-resttemplate-example/
- https://www.baeldung.com/rest-template
- https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/client/RestTemplate.html
This one covers the Maven dependencies that need to be in the pom.xml
Setting Headers
Many APIs (including, for example, https://developer.ucsb.edu) require setting headers.
For example, https://developer.ucsb.edu requires you to set:
accept: application/json
ucsb-api-version: 1.0
ucsb-api-key: value-specific-to-each-api-user
How do you set these headers? This article explains:
Related topics:
- Spring Boot: —A Java web application framework
- Spring Boot: Actuator—Checking the endpoint mappings, health or other info about your Spring Boot app
- Spring Boot: Application Properties—Defining the application.properties
- Spring Boot: ControllerAdvice—A place to factor out common ExceptionHandler, ModelAttribute and InitBinder code across multiple controllers
- Spring Boot: CSV—Downloading and Uploading CSV files with Spring Boot
- Spring Boot: Database Migrations—When you need to make a change to your database schema for an app in progress
- Spring Boot: Heroku—Tips for running with Spring Boot applications on Heroku
- Spring Boot: Logging—How to write information to the log in Spring Boot
- Spring Boot: OAuth—How to implement OAuth for authentication in Spring Boot
- Spring Boot: POST and CSRF—If you get 403 forbidden messages when using POST
- Spring Boot: Postgres—Using Spring Boot with Postgres
- Spring Boot: RestTemplate—When you need to access other APIs from the backend of your Spring Boot Application
- Spring Boot: Secrets—Ways of keepings database credentials and OAuth client secrets out of Github
- Spring Boot: Security—Authentication, Authorization and other Security issues
- Spring Boot: Sessions—How to make the stateless HTTP protocol stateful
- Spring Boot: SQL—Working with SQL and Databases in Spring Boot
- Spring Boot: VS Code—Suggested VS Code extensions for working with Spring Boot