a!httpQuery() Function

Invokes an HTTP request against a web service. Because expression functions must not have side effects, this function must only be used for invoking read-only web service operations. You must use a!httpWrite() to invoke a web service that saves, modifies, or deletes external data.

Syntax

a!httpQuery( url, method, headers, queryParameters, basicAuthenticationCredentials)

url (Text): The URL for the request.

method (Text): The http method with which to call the url. Available options are "GET" (default), "HEAD", "OPTIONS", and "TRACE".

headers (List of HttpKeyValuePair): A list of headers you wish to send as part of the request. Built with a!httpHeader().

queryParameters (List of HttpKeyValuePair): A list of query parameters you wish to add to the request. Built with a!httpQueryParameter().

basicAuthenticationCredentials (HttpAuthenticationBasic): The credentials for the request. Built with a!httpAuthenticationBasic().

Examples

Display a Grid of Weather Forecast Data Pulled From a Web API

Copy and paste the expression into the Interface Designer to test it.

load(
  local!pagingInfo: a!pagingInfo(startIndex: 1, batchSize: -1),
  with(
    local!responseBody: a!fromJson(
      jsonText: a!httpQuery(
        /* Details about the Yahoo! Weather API can be found at: https://developer.yahoo.com/weather/ */
        url: "https://query.yahooapis.com/v1/public/yql",
        queryParameters: {
          /* a!httpQuery will automatically url-encode query parameters for you, 
           * so it's OK to include spaces in the value of a query parameter */
          a!httpQueryParameter(name: "q", value: "select * from weather.forecast where woeid = 2514815"),
          a!httpQueryParameter(name: "format", value: "json"),
          a!httpQueryParameter(name: "env", value: "store")
        }
      ).result.body
    ),
    local!forecast: todatasubset(local!responseBody.query.results.channel.item.forecast, local!pagingInfo),
    a!dashboardLayout(
      firstColumnContents: {
        a!gridField(
          label: "",
          value: local!pagingInfo,
          saveInto: local!pagingInfo,
          columns: {
            a!gridTextColumn(
              label: "Date",
              field: "date",
              data: local!forecast.data.date
            ),
            a!gridTextColumn(
              label: "High",
              field: "high",
              alignment: "RIGHT",
              data: local!forecast.data.high
            ),
            a!gridTextColumn(
              label: "Low",
              field: "low",
              alignment: "RIGHT",
              data: local!forecast.data.low
            ),
            a!gridTextColumn(
              label: "Condition",
              field: "text",
              data: local!forecast.data.text
            )
          },
          totalCount: local!forecast.totalCount
        ),
        /* The terms of service for the Yahoo! weather API require attribution and the 
         * information we need for that attribution is included in the "image" field 
         * of their API's response. */
        with(
         local!attributionImage: local!responseBody.query.results.channel.image,
          a!imageField(
            labelPosition: "COLLAPSED",
            images: {
              a!webImage(
                source: local!attributionImage.url,
                link: a!safeLink(label: local!attributionImage.title, uri: local!attributionImage.link)
              )
            }
          )
        )
      }
    )
  )
)

This example uses a!fromJson to transform the HTTP response body into an Appian value. If the response body had been XML instead of JSON, we could have used torecord to do the same thing.

Display a Grid of Data Pulled From an RSS Feed

Copy and paste the expression into the Interface Designer to test it.

with(
  local!rssFeed: a!httpQuery(url: "http://www.appian.com/blog/feed").result.body,
  
  local!blogTitle: xpathsnippet(local!rssFeed, "/rss/channel/title/text()"),
  local!titles:    xpathsnippet(local!rssFeed, "/rss/channel/item/title/text()"),
  local!links:     xpathsnippet(local!rssFeed, "/rss/channel/item/link/text()"),
  local!creators:  xpathsnippet(local!rssFeed, "/rss/channel/item/dc:creator/text()"),
  
  a!dashboardLayout(
    firstColumnContents: {
      a!gridField(
        label: local!blogTitle,
        value: topaginginfo(1,10),
        columns: {
          a!gridTextColumn(label: "Title", data: local!titles, links: apply(a!safeLink(uri: _), local!links)),
          a!gridTextColumn(label: "Author", data: local!creators)
        },
        totalCount: count(local!titles)
      )
    }
  )
)

Note: it is possible to build this same grid using the xpathsnippet expression function to make the HTTP request, but it would require making 4 different HTTP requests (one for each invocation of xpathsnippet). Using a!httpQuery and storing the result in a local variable only requires one HTTP request. Additionally, the a!httpQuery() can access HTTP endpoints that require authentication and xpathsnippet cannot.

See also:

17.1

On This Page

FEEDBACK