akshays
2 years agoAce
Making multiple http.client.request third-party API requests in a single endpoint
We are integrating a third part REST API and there is a need to make multiple calls to their endpoint.
Example code:
<#assign query1 = "sampleQuery"/>
<#assign resp1=http.client.request("https","${url}","/services/data/v54.0/").
parameter("q","${query1}").
header("Authorization","Bearer "+"${accesstoken}").header("Content-Type","application/json").get() />
<#if resp1.hasError>
<#else>
<#assign sampleNumber = 4/>
</#if>
<#if sampleNumber > 2>
<#assign query2 = "sampleQuery"/>
<#assign resp2=http.client.request("https","${url}","/services/data/v54.0/").
parameter("q","${query2}").
header("Authorization","Bearer "+"${accesstoken}").header("Content-Type","application/json").get() />
<#if resp2.hasError>
<#else>
${result}
</#if>
<#else>
</#if>
In this sample code, we are making a GET request, fetching certain data and then using it to make another GET ( or PATCH, POST ) request further on.
Technically, this does produce correct results. But, would this technique cause any concerns? Are all the calls made using http.client.requests synchronous? Or, should one endpoint be used to make only one request?
Technically, this does produce correct results. But, would this technique cause any concerns? Are all the calls made using http.client.requests synchronous? Or, should one endpoint be used to make only one request?