Skip to content
AgileLogics
7 min read

Deploying to the Wolfram Cloud

Prerequisites: Associations

One function, CloudDeploy, turns code into a web API, a form, or a web page on the Wolfram Cloud. You need a Wolfram Cloud account; from a desktop session, connect with CloudConnect[] first.

A web API

(* illustrative: needs a Wolfram Cloud account *)
api = CloudDeploy[
  APIFunction[{"x" -> "Integer"}, #x^2 &],
  "square-api",
  Permissions -> "Public"]

The result is a CloudObject with a URL like https://www.wolframcloud.com/obj/yourname/square-api. Anyone can call it:

https://www.wolframcloud.com/obj/yourname/square-api?x=7

and gets back 49. From the Wolfram Language, URLExecute[api, {"x" -> 7}] does the same.

  • {"x" -> "Integer"} declares a parameter and its type. The type is an interpreter: the cloud rejects values that aren't integers before your code runs. Other types include "Number", "String", "Date", and "Country".
  • Parameters reach the function as an association, so #x is the value.
  • Permissions -> "Public" makes it callable without signing in; the default is private.

Returning JSON

(* illustrative *)
CloudDeploy[
  APIFunction[{"n" -> "Integer"},
    ExportForm[<|"n" -> #n, "square" -> #n^2, "prime" -> PrimeQ[#n]|>, "JSON"] &],
  "number-info",
  Permissions -> "Public"]

Calling it with ?n=7 returns a JSON object with n, square (49), and prime (true). ExportForm chooses the response format — JSON, PNG for a plot, HTML, and more.

A web form

(* illustrative *)
CloudDeploy[
  FormFunction[{"name" -> "String", "year" -> "Integer"},
    "Hello, " <> #name <> "! You will turn " <>
      ToString[2030 - #year] <> " in 2030." &],
  "greeting-form",
  Permissions -> "Public"]

Visitors see a form with two fields, validated by type; submitting it shows the result.

More deployment options

  • CloudPublish[notebook] publishes a notebook as a web page.
  • CloudDeploy[Manipulate[...]] makes an interactive web app.
  • CloudDeploy[ScheduledTask[code, "Daily"]] runs code on a schedule — for example, to fetch data and email a report.
  • Databins (CreateDatabin, DatabinAdd) collect data sent from devices and other programs.
  • For your own servers, the Wolfram Application Server runs the same APIs on-premises or in Kubernetes.

Security

  • Always declare parameter types — never accept raw text and pass it to ToExpression, which would let callers run arbitrary code.
  • Keep deployments private unless they must be public, and use Permissions to grant access to specific users.
  • Deployed code runs under your account and uses your cloud credits; limit expensive operations.