Control Web Response for Space Station Tracker
You can control the exact features of the HTTP response from a cloud object by returning an HTTPResponse. Error conditions can be handled with HTTPErrorResponse.
Define a function that finds the city closest to the current location of the International Space Station. The space station moves quickly, so the results change rapidly.
show complete Wolfram Language input
In[2]:=
issLocationDisplay[]
Out[2]=
Deploy a cloud object that computes the result each time, using HTTPResponse to indicate the content type and to specify a header that tells the browser not to cache the result.
In[3]:=
obj = CloudDeploy[
Delayed[HTTPResponse[
ExportString[issLocationDisplay[], "PNG"], <|
"ContentType" -> "image/png",
"Headers" -> {"Cache-Control" -> "no-cache"}|>]],
CloudObject["iss-location"], Permissions -> "Public"]
Ban certain users from using the cloud object, returning an HTTPErrorResponse.
In[4]:=
obj = CloudDeploy[Delayed[
If[MemberQ[{"badapple@example.com", "blackhat@example.com",
"spammer@example.com"}, $WolframID],
HTTPErrorResponse[403],
HTTPResponse[
issLocationDisplay[], <|
"Headers" -> {"Cache-Control" -> "no-cache"}|>]
]], CloudObject["iss-location"], Permissions -> "Public"]