Deploy a Web API
Make Wolfram Language functions available as cloud APIs that can be called from other programming languages or embedded on webpages.
Create an APIFunction
Create an APIFunction that returns the distance between two cities. In this example, TravelDistance returns a Quantity. Applying QuantityMagnitude to that result extracts just the numeric value, which is easier for an external program to process than a Quantity:
Deploy the APIFunction to the Wolfram Cloud
Deploy the function to the cloud with Permissions->"Public" to make the API available to anyone:
Test the API from a browser
Verify that an API works as you expect it to by calling it from a browser. To construct a URL that calls the API, right-click the URL in the CloudObject output of CloudDeploy and choose Copy Address:
Paste the address into a browser search field and append a question mark (?) followed by the names and values of the parameters separated by ampersands (&)—for example, "?city1=Chicago&city2=Miami":
Call the API from a non-Wolfram language
Get the code for calling the API from Python:
Paste the embed code into a Python script:
Run the Python script:
$ ./APITest.py
1378.25516483735
Notes
- For HTTP POST requests, use HTTPRequest with Method "POST" instead of URLExecute.