How to make AJAX requests to external services

We will use the Weather Underground service to show how to make Ajax requests to third party services. This service provides a rest API (documented at, but it is impossible to access this API using normal Ajax request (using XMLHttpRequest) due browsers applying the “Same Origin Policy” to JavaScript code. Fortunately, WireCloud provides the MashupPlatform.http.makeRequest method for dealing with this problem. A possible way to access to this API is by using the following code:

var getForecastByCoord = function getForecastByCoord(
) {
    var url;
    if (typeof onSuccess !== "function" || typeof onError !== "function") {
        throw new TypeError();
    url =
        "" +
        API_KEY +
    url += + "," + coord.lon;
    url += ".json";
    MashupPlatform.http.makeRequest(url, {
        method: "GET",
        onSuccess: function(response) {
            var forecast_data;
            forecast_data = JSON.parse(response.responseText);
            if (forecast_data.error) {
            } else {
        onError: function() {

The getForecastByCoord function makes the appropriated request to Weather Underground and passes the result to the onSuccess callback.