How external API requests work in a functional stack

Options

If I add an external API request in the middle of a stack at Step X, will my functional stack wait for a response from this API request before going further or it will just hit and move forward? I have an API (used to send a Whatsapp message) that sometimes takes time. Its response is irrelevant to the rest of the stack. I don't want my functional stack to get delayed because of this sluggish API.

Best Answers

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Answer ✓
    Options

    Hi @vk - yes your Function Stack will wait for the external API request to finish before continuing on through the stack. However, if the response is irrelevant to the rest of the stack, you could try to set the timeout setting of the external API request call to very low. The function will timeout and continue down the rest of the function stack but the external call should be "Triggered".

  • Chris Coleman
    Chris Coleman Administrator

    ADMIN

    Answer ✓
    Options

    Sure. In the below example, I'm first defining a message payload, and then using axios to make a POST request to my API.

    const payload = { phone: "recipient", text: "message"};
    axios.post('https://myapi.com/webhook', payload);

    Of course, the exact structure of the request will be dependent on the API you are using. It's hard for me to give exact instruction based on the Whatsapp API as I'm not directly familiar, but using Axios to make the call is pretty straight forward. As a non-dev like myself, I honestly lean on ChatGPT a lot to write my code if the API documentation doesn't provide sample code for me.

Answers