Skip to content

http get

andy.rothwell edited this page Aug 27, 2018 · 10 revisions

http-get dataSources

'http-get' is the most generic type of dataSource retrieval, and should be used for any simple ajax call which returns json data.

You can add parameters to the ajax call by adding them to 'options-params' in the config.

Example:

dataSources: {
  // each source has a unique key, e.g. `opa`
  opa: {
    // the type of call to make
    type: 'http-get',
    // the base url of the api
    url: 'https://data.phila.gov/resource/w7rb-qrn8.json',
    // all options
    options: {
      // query string parameters to be added to the url
      params: {
        // each param is mapped to a function that gets passed the current
        // address feature. use attributes from this feature to form data queries.
        // in this case, a param of `?parcel_number=<opa_account_num>` will be
        // appended to the url.
        parcel_number: function (feature) { return feature.properties.opa_account_num; }
        },
      // a callback that unpacks the desired record(s) from the api. this
      // data will be kept in state and made available in the topic panel.
      success: function (data) {
        return data[0];
      }
    }
  }
},
Clone this wiki locally