Create an additional database connection

In this section, you will create a connection to an additional database of information, which will provide information related to the record being inserted in the weatherwatchers database, thus enhancing the data recorded.

  1. Drag the Operation-Switch policy onto the Assemble line before the Weatherwatchers Invoke.
  2. Select get /reports for case 0.
  3. Click + Case. Then, select post /reports for the operation.
  4. Close the operation-switch configuration pane. Drag the existing Weatherwatchers invoke icon down onto the get /reports line.
  5. Drag a set-variable policy action onto the Assemble line for the post /reports operation path.
  6. In the Set Variable configuration pane, enter location in the Set field. Enter lat=x&lon=y in the Value field. Then, close the Configuration pane.
  7. Drag a gatewayscript policy action onto the line after the Set Variable.
  8. Enter the following code to examine the inbound report and set the variable value to the latitude and longitude values that are contained in the report. The comments shown in the illustration are optional.
    var nlatlon = \"lat=\" + apim.getvariable('request.body').location[0] + \"&lon=\" + apim.getvariable('request.body').location[1];
    apim.setvariable('latlon', nlatlon);

  9. Close the gatewayscript configuration page. Drag an invoke policy action onto the line after the gatewayscript.
  10. Set the URL to:$(latlon)
  11. Save your changes. Then, click the test arrow.
  12. Click Republish product.
  13. Select the post /reports operation.
  14. Scroll down and enter a sample weatherwatcher forecast. Here is a sample:
    {"location":[34, 45],
    "observed":"Hot rainy low 70 high 90",
    "watcher":{"name":"Bob", "email":"[email protected]", "city":"Here"}}
  15. Click Invoke.

    The result contains a forecast for the location.
  16. Close the Test pane.