How to | Create an Instant API

An instant API lets you call Wolfram Language code in the Wolfram Cloud from a web URL. You create an instant API and deploy it on the web using the Wolfram Language functions APIFunction and CloudDeploy. Instant APIs can be private (so only you can use them) or public (so anyone can use them). Note: running an instant API uses Wolfram Cloud Credits from your account.

This sets up an API that finds the square of an integer and deploys it to the cloud:

In[1]:=
Click for copyable input
Out[1]=

Here is how you can run the API from a web browser:

    

An API requires three things: a specification of parameters and their types, a specification of the code the API should run, and a specification of how the result from the API should be returned.

The Wolfram Language supports many types of parameters, as listed here.

This creates an instant API that has a parameter called representing a country and that returns a PNG:

In[1]:=
Click for copyable input
Out[1]=

Here is the result from calling the API from a web browser:

    

You specify the code for an API to run as a pure function, with parameter names given as and an at the end to indicate that it is a pure function.

This deploys an instant API that uses parameters and as numbers and whose code adds these numbers together:

In[1]:=
Click for copyable input
Out[1]=
    

You can specify permissions for an API deployment; this makes the API public:

In[1]:=
Click for copyable input
Out[1]=
    

If you call an API without parameters in a web browser, you get a form:

    

One way to debug an API is to run it entirely within the Wolfram Language. An APIFunction works like a pure function that takes an association as its argument:

In[1]:=
Click for copyable input
Out[1]=