Make an API and a Web Form from the Same Function
Create a simple APIFunction to compute factorials.
In[1]:=
api = APIFunction["n" -> "Integer", #n! &]
Out[1]=
What if you want both an APIFunction for another website and a FormFunction for actual users visiting the website directly? Note that since FormFunction and APIFunction have the same signature, you do not have to rewrite any code.
In[2]:=
CloudDeploy[URLDispatcher[{
"/api" -> api,
"/form" -> FormFunction @@ api
}],
"user:documentation@wolfram.com/application"
]
Now you can visit https://www.wolframcloud.com/objects/documentation@wolfram.com/application/api?n=10 to use the API.
Or you can visit https://www.wolframcloud.com/objects/documentation@wolfram.com/application/form to use the form directly.