简体   繁体   中英

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.

How about building your target URL as follows:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM