Developing with ArcGIS Open Data

Mike Juniper :: Washington DC R&D Center

Brooks Robertson :: Washington DC R&D Center

Daniel Fenton :: Washington DC R&D Center

mjuniper.github.io/presentations/opendata-api.html

ArcGIS Open Data

Interoperability

koop

Feature Services from APIs

  • Open Source (github.com/Esri/koop) R & D
  • node js
  • geojson (& others)    ==>    feature services
  • feature services    ==>    geojson
  • export as kml, csv, shp

Socrata

OpenSearch & DCAT

Daniel Fenton

Open Data API

Brooks Robertson

What is an API?

"In computer programming, an application programming interface (API) is a set of routines, protocols, and tools for building software applications. An API expresses a software component in terms of its operations, inputs, outputs, and underlying types."

Totally clear right?

Simple API example

  1. http://opendata.arcgis.com
  2. /datasets
  3. .json
  4. ?q=water&sort_by=relevance&page=1

OpenData V1 API (beta)

HTTP protocol (GET, POST, PUT, DELETE)

opendata.arcgis.com

OR

imap.maryland.opendata.arcgis.com

Available resources /datasets, /sites
JSON format

Who consumes the OpenData API?

  • Opendata "Umbrella" (Backbone)
  • OpenData Custom Sites (Backbone)
  • OpenData Admin (Angular)

OpenData V2 API (public)

Versioning via URL or Headers

/api/v2/...

Accept: application/vnd.arcgis+json; version=2

OpenData V2 API (public) continued..

Consistent return of an object or list of objects based on resource

/api/v2/datasets.json -> {"datasets": []}

/api/v2/datasets/:id.json -> {"dataset": {}}

OpenData V2 API (public) continued..

Authenticated access
Caching via Etag and If-None-Match header
Appropriate HTTP Status codes
Well documented

What can you do with it?

Build an app!


$.getJSON('http://my.api.url')
  .done(function (response, status, xhr) { 
    /* stuff it into the DOM... */ 
  })
  .fail(function (xhr, status, error) { 
    /* do something about the error! */ 
  });
          


$.getJSON('http://my.api.url')
  .done(function (response, status, xhr) { 
    /* do something with the response! */ 
  })
  .fail(function (xhr, status, error) { 
    /* do something about the error! */ 
  });
          

MV*

Choosing the Best JavaScript Framework for You

Friday, 13 Mar 2015, 1:00pm - 2:00pm

Key endpoints:

/datasets.json?q=<search string>&page=<page number>

$.getJSON(MyApiUrl + '/datasets.json?q=water&page=1');

and

/datasets/<id>.json

$.getJSON(MyApiUrl + '/datasets/abc123.json');

And maybe:

/datasets/<id>/related.json

$.getJSON(MyApiUrl + '/datasets/abc123/related.json');

And:

/datasets/autocomplete?query=<search string>

$.getJSON(MyApiUrl + '/datasets/autocomplete?query=wat');

Also:

/datasets/<id>.csv

/datasets/<id>.geojson

/datasets/<id>.kml

/datasets/<id>.zip

Errors...


$.getJSON('http://my.api.url')
  .done(function (response, status, xhr) { 
    if (response.error) {
      /* you don't have to do this! */
    }
  })
  .fail(function (xhr, status, error) {
    switch (xhr.status) {
      case 404:
        /* handle 404 */
      default:
        /* handle other errors */
    }
  });
          

Gotcha's:

  • Currently no JSONP support
  • Does support CORS
  • But ... IE < 10

Ok,... how?

              
                $ git clone
                $ cd opendata-backbone
                $ npm install
                $ bower install
                $ gulp serve
              
            

In backbone-land...


DatasetCollection = Backbone.Collection.extend({
  
  url: function () {
    //get the params (q=, page=, etc) from somewhere...
    var queryParams = '';
    return MyOD.config.api + 'datasets.json?' + queryParams;
  },

  parse: function (resp) {
    return resp.data;
  }

});
          
and

DatasetModel = Backbone.Model.extend({
  
  url: function () {
    return MyOD.config.api + 'datasets/' + this.get('id') + '.json';
  },

  parse: function (response) {
    return response.data;
  }
  
});
            

More to come?

Rate This Session

www.esri.com/RateMyDevSummitSession