Make an API and a Web Form from the Same Function
Create a simple APIFunction to compute factorials.
In[1]:=
![Click for copyable input](assets.en/make-an-api-and-a-web-form-from-the-same-function/In_3.png)
api = APIFunction["n" -> "Integer", #n! &]
Out[1]=
![](assets.en/make-an-api-and-a-web-form-from-the-same-function/O_3.png)
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]:=
![Click for copyable input](assets.en/make-an-api-and-a-web-form-from-the-same-function/In_4.png)
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.
![](assets.en/index.en/GB_5.png)
Or you can visit https://www.wolframcloud.com/objects/documentation@wolfram.com/application/form to use the form directly.
![](assets.en/index.en/GB_6.png)