API Developer
In this section, you will configure the assembly for the store locator resource. You will use GatewayScript to modify the response to your consumers, providing them a maps link to the nearest store location.

Configure the get.stores Case:

This operation will call out to the Google Geocode API to obtain location information about the provided zip code, then utilize a simple gatewayscript to modify the response and provide a formatted Google Maps link.

  1. Add an invoke policy to the get.stores case.

  2. Edit the new invoke action with the following properties:

    Title: invoke_google_geolocate

    URL: https://maps.googleapis.com/maps/api/geocode/json?&address={zip}

    Stop on error: unchecked

    Response object variable (scroll to the bottom): google_geocode_response

  3. Click the X to close the invoke editor.

  4. Add a gatewayscript policy with the following properties:

    Title: gws_format_maps_link

    Copy the following GatewayScript snippet and paste it into the text area:

    // Save the Google Geocode response body to variable
    var mapsApiRsp = apim.getvariable('google_geocode_response.body');
    
    // Get location attributes from geocode response body 
    var location = mapsApiRsp.results[0].geometry.location;
    
    // Set up the response data object, concat the latitude and longitude  
    var rspObj = {
      "google_maps_link": "https://www.google.com/maps?q=" + location.lat + "," + location.lng  
    };
    
    // Save the output  	
    apim.setvariable('message.body', rspObj);
    

  5. Click the X to close the gatewayscript editor.

  6. Your assembly for the logistics API will now include two separate operation policies:

  7. Save your changes.

  8. Click on the <- All APIs link to return to the draft APIs list.

Conclusion

Congratulations! You have successfully configured two new API’s with advanced assemblies. In the next lab, you will bundle the API’s into a Product and publish it to the consumer portal.

Proceed to Lab 6 - Working with API Products.