user18665270
user18665270

Reputation: 69

Consume REST API with parameters in another REST API

@GetMapping(path = "/api/v1/{id}/{status}")  *** Line -1 
public String getEmployeeStatus(@PathVariable(value = "id") String id,
            @PathVariable(value = "status") String status)
{
   // here i want to call other REST API. But i want to pass path variables like {id} and {status} to the consuming API/Client URL.
        String clientURL=  "/api/employees/v1/{id}/employee/{status}"
        String name = "abc";
        String password = "bac";
        String authString = name + ":" + password;
        String authStringEnc = new String(Base64.getEncoder().encode(authString.getBytes()));
        String authorizationHeader = "Basic " + authStringEnc;
        Client restClient = Client.create();
        WebResource webResource = restClient.resource(clientURL);  *** line 14

        ClientResponse resp = webResource.accept("application/json").header("Authorization", "Basic " + authStringEnc).get(ClientResponse.class);

}

@line -14, i want to pass {id}, {status} to the client URL from my GET API(line 1). i dont know how to pass these values to the consuming api.

how to add even if i get clientURL from properties file.

Upvotes: 0

Views: 1317

Answers (1)

cloooze
cloooze

Reputation: 173

How about building your target URL as follows:

String clientURL=  String.format("/api/employees/v1/%s/employee/%s", id, status);

Upvotes: 1

Related Questions