Wolfram Language

Open live version

Make a Capital Temperature URL

Make a URL that returns the current temperature of the capital of a given country.


code

CloudDeploy[APIFunction[{"country" -> "String"}, WeatherData[CountryData[#country, "CapitalCity"], "Temperature"] &], Permissions -> "Public"]

how it works

This expression gives the current temperature of the capital of Germany:

WeatherData[CountryData["Germany", "CapitalCity"], "Temperature"]

To make a URL that gives the current temperature of the capital of an arbitrary country, use APIFunction to specify the name of a query string field (country) and map it to the value country. Deploy to the cloud via CloudDeploy.

obj = CloudDeploy[APIFunction[{"country" -> "String"}, WeatherData[CountryData[#country, "CapitalCity"], "Temperature"] &], Permissions -> "Public"]

This hyperlink visits the page to get the temperature of the capital of Germany:

Hyperlink[URLBuild[First[obj], {"country" -> "Germany"}]]

You can use the cloud function like any other Wolfram Language function from within the cloud or from the desktop:

URLFetch["https://www.wolframcloud.com/objects/e6c7b2c4-50e5-417a-\ 8fc6-9a01f2647817?country=Germany"]