Forum Discussion

ronaksomani's avatar
9 years ago

http.client.request to make a POST call to external API from lithium

Hi,   I am using http.client.request freemarker object to make a POST call to an external API from Lithium endpoint. I am using basic auth to authenticate the call.  Request looks as below : http...
  • YuriK's avatar
    9 years ago

    Hey ronaksomani,

     

    To answer your second question, you can just chain .header calls to add multiple headers, so something like:

     

    http.client.request("https","api.something.com","url.something").header("Authorization", "Basic encodedcreds").header("header2", "header2value").body("{'param1':'value1','param2':'value2'}","application/json").post() />

    As for the timeout, how long does your http request take if you do a curl request to the same endpoint you are trying to hit with http.client? Our default timeout is 5 seconds, so if it takes longer to get a response then it will timeout. We can increase it for you, but depending on your use case, you may not want to have the endpoint take longer than that.

     

    Hope this helps,

     

    Yuri