Wolfram Language

Cloud & Web Interfaces

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
Click for copyable input
issLocationDisplay[] := Module[{pos, posline, country, city, distance}, {pos, posline} = SatelliteData[ Entity["Satellite", "25544"], {"Position", "PositionLine"}]; country = First[GeoNearest["Country", pos]]; distance = Round[GeoDistance[pos, country], 0.1]; Panel@Column[{Row[{"ISS Position: ", Style[If[distance <= Quantity[0., "Miles"], "over " <> First[GeoNearest["City", pos]]["Name"] <> ", " <> country["Name"], ToString[ Row[{"over the open sea ", distance, " from ", country["Name"]}]]], Darker[Blue]]}, BaseStyle -> Directive["FontFamily" -> "SansSerif", RGBColor["#497CA4"], Larger, Bold]], GeoGraphics[{Gray, Thickness[.005], Arrowheads[{{0.05, 0.4}, {0.05, 0.13}}], Arrow @@ posline, Red, PointSize[.01], Point[pos], Opacity[.1], Black, GeoVisibleRegion[pos]}, GeoCenter -> pos, GeoRange -> "World", ImageSize -> 600]}]]
Click for copyable input

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.

Click for copyable input
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.

Click for copyable input
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"]

Related Examples

de es fr ja ko pt-br ru zh