MapQuest API

From DreamFactory
Jump to: navigation, search

This tutorial shows how to configure a remote web service to connect to the Twilio API. It shows how to pass your authorization header to the remote service. This example is specific to the Twilio API, but many APIs have similar concepts.

Create the Remote Web Service

  • Sign up for a free MapQuest developer account here.
  • In the DreamFactory admin console, go to the Services tab and click Create.
  • Set the Service Type to 'Remote Service' > 'HTTP Service'
  • Set the service name to 'mapquest_geocoding'.
  • Set the service label to 'MapQuest Geocoding API'. Check the Active checkbox.
  • Go to the Config tab for the new service and set the Base URL to http://www.mapquestapi.com/geocoding/v1.
  • Under Parameters, click the '+' button and enter 'key' for Name and '<your-mapquest-api-key>' for Value. Make sure to check 'Outbound' and select all five HTTP verbs so that the API key is sent to the MapQuest API for all requests.

Mapquest-http-service.png

  • Optionally, go to the Service Definition tab and copy in a Swagger 2.0 JSON definition for many of the important Twilio API calls. The Swagger 2.0 JSON file for the Twilio API is located here.

Twilio-http-swagger.png

  • Click Create Service to save your new service.

Call the Remote Web Service

You can now use any REST client to access your remote web service using the DreamFactory REST API. See other tutorials for authentication options.

For example, with cURL you can first log in as a DreamFactory admin and get a session token:

curl -i -k -3 -X POST "http://localhost:8080/api/v2/system/admin/session" -d '{ "email" : "[email protected]", "password" : "your_password" }' -H "Content-Type: application/json"

Then make a cURL call to the Twilio API, like this:

curl -i -k -3 -X GET "http://localhost:8080/api/v2/twilio/Accounts/<your twilio account sid>.json" -H "X-DreamFactory-Api-Key: <api key for the admin app in the apps tab>" -H "X-DreamFactory-Session-Token: <session token returned by the login api call above>"

DreamFactory combines the request URL from the client with the configured base URL for the service to generate the actual URL for the request.

If you're using the Swagger 2.0 JSON or YAML definition for the Twilio API, you can easily add role-based access control to the Twilio API in the 'Roles' tab of the DreamFactory admin console.

Remember that you can also create server-side scripts to manipulate the API request or response.