unable to find information on how can i call a external rest API which is not in API HUB and uses OAUTH2
karthiklove opened this issue · 3 comments
When i check the documentation it looks like for using REST API, we have to use generator to generate the code for api and then cll it.
In my case i just want to directly call an external rest API via destination and want cloud sdk to handle the oauth token handling.
Could you please help with the details or point me to the section in the documentation, if i have missed it.
If you don't need the convenience of a REST
or OData
client, but just want the OAuth token flow to be handled while fetching destinations, you could use the DestinationAccessor
to fetch the destination.
This will look up the destination in the destination service if the application is running in Business Technology Platform(BTP).
The OAuth flow is taken care of the destination service internally and the resulting authorization information will be included in the response.
After fetching the destination using the DestinationAccessor
, you could use our HttpClientAccessor
to obtain a HttpClient
based on the destination and then use this client to execute your desired REST calls.
HttpDestination destination = DestinationAccessor.getDestination("my-destination").asHttp();
HttpClient client = HttpClientAccessor.getHttpClient(destination);
I have given examples in Java as you didn't mention the language you are currently using. The same concepts apply in JS/TS. Here is the associated documentation for Java and JS.
Regards,
Kavitha
thanks a lot Kavitha, could you please share how to trigger the actual call, is it something client.get or client.trigger
it's client.execute(..). Please refer to the javadoc of HttpClient
for more info.