Consume the Watson Translator service

In this section, you will modify the REST API to invoke the Watson Language Translator service’s Language Identification method.

    1. Open the flow editor in your instance of Node-RED.

    1. Delete the connections between the last three nodes by clicking the connectors and pressing Delete on your keyboard.

    1. Drag and drop a function node onto the canvas.

    1. Drag and drop the language identify node onto the canvas.

    1. Wire the nodes together.

    1. Double-click the new function node and enter code that takes the input from the REST call and makes it available for the Language Identify service to use. Enter this information and then click Done:
      • Name: Extract Input
      • Function: msg.payload = msg.req.body.msgdata; return msg;

    1. Double-click the second function node and add code that will send the response from the language identification service back to the client that is invoking the service. Enter this information and then click Done:
      • Name: Process Output
      • Function:msg.payload = {};

        msg.payload.identifyresponse = "I don’t know";

        if (msg.lang && msg.lang.language){

        msg.payload.identifyresponse = msg.lang.language;

    1. Deploy your changes.
    2. Test your application by entering text other than English, such as Spanish text. Try other languages.

You now have a REST API that invokes the Watson Translator Language Identification method and an HTTP web application that invokes this API.