MapQuest API

From DreamFactory
Jump to: navigation, search
Line 26: Line 26:
 
<pre>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"</pre>
 
<pre>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"</pre>
  
Then make a cURL call to the Twilio API, like this:
+
Then make a cURL call to the MapQuest API, like this:
<pre>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>"</pre>
+
<pre>curl -i -k -3 -X GET "http://localhost:8080/api/v2/mapquest_geocoding/address?location=100%20Park%20Ave%2C%20New%20York%2C%20NY%2010017" -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>"</pre>
  
 
DreamFactory combines the request URL from the client with the configured base URL for the service to generate the actual URL for the request.  
 
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.  
+
If you're using the Swagger 2.0 JSON or YAML definition for the MapQuest API, you can easily add role-based access control to the MapQuest API in the 'Roles' tab of the DreamFactory admin console. You can also add Swagger definitions for other MapQuest APIs endpoints, such as the predictive search API [https://github.com/dreamfactorysoftware/df-service-apis/blob/master/mapquest/mapquest_search_ahead.json here].
  
 
Remember that you can also create server-side scripts to manipulate the API request or response.
 
Remember that you can also create server-side scripts to manipulate the API request or response.

Revision as of 17:13, 14 September 2016

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 the MapQuest Geocoding API. The Swagger 2.0 JSON file for the MapQuest Geocoding AP is located here.

Mapquest-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 MapQuest API, like this:

curl -i -k -3 -X GET "http://localhost:8080/api/v2/mapquest_geocoding/address?location=100%20Park%20Ave%2C%20New%20York%2C%20NY%2010017" -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 MapQuest API, you can easily add role-based access control to the MapQuest API in the 'Roles' tab of the DreamFactory admin console. You can also add Swagger definitions for other MapQuest APIs endpoints, such as the predictive search API here.

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