Digital Assistant and Mobile

Get Involved. Join the Conversation.

Topic

    Luuk
    Consuming an external API from a embedded container Custom...Answered
    Topic posted March 14, 2019 by Luuk Bronze Crown: 15,000+ Points, tagged Bots 
    48 Views, 1 Comment
    Title:
    Consuming an external API from a embedded container Custom Component
    Summary:
    Consuming an external API from a embedded container Custom Component
    Content:

    Hi all,

    There's a lot of information online about how to create a custom component in an embedded container.
    Great stuff and it works really well but the challenge I'm facing now is that I'd like to consume an external API from within the custom component. Does anyone know where to find a basic example of that?

    Thanks in advance.
    Kind regards,
    Luuk

    Best Comment

    Luuk

    Ok I think I've just found it.

    I'm putting the info here for others to find.

    You'll need to install the node module request. Go to your project folder in your CLI and type:

    npm install request --save

    This installs the request module into the node_modules folder

    You can now use the request module in your custom component like this:

        var request = require('request');
            request("http://www.google.com, function (error, response, body) {
              console.log('error:', error); // Print the error if one occurred
              console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
              console.log('body:', body); // Print the HTML for the Google homepage.
            });

     

     

    Comment

     

    • Luuk

      Ok I think I've just found it.

      I'm putting the info here for others to find.

      You'll need to install the node module request. Go to your project folder in your CLI and type:

      npm install request --save

      This installs the request module into the node_modules folder

      You can now use the request module in your custom component like this:

          var request = require('request');
              request("http://www.google.com, function (error, response, body) {
                console.log('error:', error); // Print the error if one occurred
                console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
                console.log('body:', body); // Print the HTML for the Google homepage.
              });