Plumber API response sent to another API

Hi

Has anyone here had any success with designing and implementation of a performant method to pass a response from one plumber API to another plumber API? These APIS are deployed on RSConnect and I'm stuggling to work out the best way forward.

We have API 1 that requests two parameters and returns a list of data items.
User will then select the rows from the returned list they want to send to API 2.
Depending on the values in the rows selected, we may want to pass those to API 2 and or API 3.
We currently have seperate APIs not one API with seperate endpoints within.

So in short what the best way to pass parameters to an API from the response of another API?

Currently we are doing the following as sample of API 1 to call API2, which instinct tells me is not the best way;


library(httr)
library(jsonlite)

##################################### THE API DETAILS #####################################

# needs to be post to allow body to be sent
#* @apiTitle Invoke API from this API
#* @apiDescription TESTING
#* @serializer unboxedJSON
#* @apiVersion 1.2
#* @apiProduces "application/json"

####################################  DEFINE PARAMETERS FOR ENDPOINT ###########################

#* @param sString1:str
#* @param sString2:str
#* @post /search/stringSearch
#* @get /search/stringSearch


################################### FUNCTION WITHIN API GET DATA FOR POSTCODE SUPPLIED FUNCTION ###############

function(sString1 = 'UNK',sString2 = 'UNK', req) {
          resp <-
          httr::POST(
            url = "...../search/API2Search",
            body = jsonlite::toJSON(list(api2_string1 = sString1, api2_string2 = sString2)),
            add_headers(Authorization = paste0("Key ", Sys.getenv("CONNECT_API_KEY")))
          )
        
        resp_time<-resp$times[6]
        
        response_data <- fromJSON(rawToChar(resp$content), flatten = TRUE)
        
        return(paste0(response_data$VAL[1]
                      ," response took ", resp_time
                      , " seconds"))
}


############################################################################################

Thanks in advance!

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.