Use Case: Internal API Calls with Manual Clients

1. Service-1 calling Service-2 GET API

Dependencies

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.30</version>
    <scope>provided</scope>
</dependency>

Sample Service 2

SampleController.java

application.yaml

Build and run the service 2 application.

Sample Service 1

ResttemplateConfig.java

SampleController.java

application.yaml

Build and execute the application

  • Call the Service 1 API using Postman

Log Request & Response using Default httpclient

We can enable basic information logging like request, headers, response code etc by setting logging level below

logging.level.org.springframework.web.client.RestTemplate=DEBUG

  • We can enable full logging including request, response body, etc using Apache HttpClient

Log Request & Response using Apache httpclient

Add below dependency

Update RestTemplate config to use HttpComponentsClientHttpRequestFactory() request factory of Apache HTTPClient

Add below logging property in application.yaml

Run both the service 1 and service 2 application from above example

Run the service 1 API from Postman and monitor the logs

Logs

Last updated