Skip to content

http client.js

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

http-client.js

Functions

fetch

The fetch() function is called if a datasource uses "type: 'http-get'". For 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];
    }
  }
}

The function takes the following parameters:

parameter description or example
feature
dataSource
dataSourceKey
targetIdFn

The function does a basic ajax call against an API.

fetchNearby

The fetchNearby() function is called if a datasource uses "type: 'http-get-nearby'". For example:

export default {
  id: 'crimeIncidents',
  type: 'http-get-nearby',
  url: 'https://phl.carto.com/api/v2/sql',
  options: {
    table: 'incidents_part1_part2',
    dateMinNum: 1,
    dateMinType: 'year',
    dateField: 'dispatch_date',
  }
}

The function takes the following parameters:

parameter description or example
feature
dataSource
dataSourceKey
targetIdFn

This function finds nearby features.

fetchMore

The fetchMore() function is called by the fetchMoreData() function of data-manager.js.

The function takes the following parameters:

parameter description or example
feature
dataSource
dataSourceKey
highestPageRetrieved
Clone this wiki locally