Search code examples
node.jsdataflowtotal.js

dynamic route for http-request in total.js flow


How to use dynamic url for http-request in total.js flow. I am able to get params from route component but how to pass this to http-request url ?

enter image description here


Solution

  • It's possible and it's very easy. You can use Code (better) or Repository component.

    • add Code component with this code:
    // This will be as dynamic argument stored in hidden Flow Message repository:
    repository.code = 'sk';
    
    // or you can bind value from received data:
    repository.code = value.code; // value === received data
    
    // Continue with processing
    send(0, value);
    
    • now you can update URL address in HTTP Request component like this:
    URL: https://restcountries.eu/rest/v2/alpha/{code}
    

    HTTP Request component will replace {code} for repository.code value. You can use multiple values. That's all :-)