Create an API

InterPlay API setup creates a simple HTTP mount point that receives a query parameter and performs any operation. 

In this example, the API receives a query parameter and then searches the index. 

Steps:

1. Select ‘HTTP In‘ node under the Components section and then drag and drop it onto the white space. The HTTP node provides an input node for HTTP requests, allowing the creation of simple web services. 

  Double clicks on ‘HTTP’ node and enter the following:

  Method: GET

  URL: /getBBData

  Name: HTTP getBBData

2. Select the ‘Function’ node under the Components section and then drag and drop it onto the white space. This function can either return the messages it wants to pass on to the next nodes in the flow, or it can call node.send(messages). The purpose of this function is to extract the query parameter from the incoming HTTP request.  Add the following code into the Function node. 

3. In this example, API will search the Algolia index for the given search keyword. Therefore, select ‘Algolia’ node under ‘Startups’ and drag and drop it to the white space. You will need an Algolia API_ID and API_Key for the implementation of flow. Enter the Index name that was created in Algolia that holds the data. If Algolia is not set up at this point, you can use another startup or function to return the HTTP response. 

4. Similar to step 4 above, create another ‘Function‘ node called ‘JSON Formatter’. The JSON Formatter Node is passed in a message through the JavaScript object msg. The node then formats the object into JSON and gets it ready to pass to the HTTP Response Node.

7. Finally, select the ‘HTTP response’ node from the ‘Components‘ section and drag it to the white space. This is the response node that will pass the response message to the HTTP request. 

5. After connecting all nodes as shown below, the flow can be deployed. 

6. The API is ready to be consumed at the endpoint ms2.iterate.ai:port/getBBData. Here the port number is the port where your specific interplay app is running. This port number can be observed on the top right side above the interplay screen. 

Was this article helpful?

Related Articles

Leave A Comment?