Skip to content

http get

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

http-get type dataSources

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

parameter description or example
type
url
options

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

parameter description or example
params
success

NonBundled Project 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];
      }
    }
  }
},

Bundled Project Example:

export default {
  id: 'opa',
  type: 'http-get',
  url: 'https://data.phila.gov/resource/w7rb-qrn8.json',
  options: {
    params: {
      parcel_number: function(feature) { return feature.properties.opa_account_num; }
    },
    success: function(data) {
      return data[0];
    }
  }
}
Clone this wiki locally