Skip to content

Instantly share code, notes, and snippets.

@chrismetcalf
Created December 8, 2012 06:52
Show Gist options
  • Save chrismetcalf/4238976 to your computer and use it in GitHub Desktop.
Save chrismetcalf/4238976 to your computer and use it in GitHub Desktop.
#acApps 2012 Code Snippets

#acApps 2012 Code Cookbook

Big congrats to our winners!

Handy Tools & Resources

Examples

Sheriff Crime Data

Crime report data is only available as a download, but the downloaded format is still pretty useful. Direct links:

Querying Parks Data by City

GET data.acgov.org/resource/k9se-aps6.json?city=Alameda

Using JSONP (for cross-domain JavaScript)

Use the $jsonp parameter to set your callback function name:

http://data.acgov.org/resource/k9se-aps6.json?city=Alameda&$jsonp=jsonp_callback_name

From jQuery:


$.ajax({
  url: "http://data.acgov.org/resource/k9se-aps6.json?city=Alameda",
  jsonp: "$jsonp"
})
...

Tips

RESTful Resources

  • Accessed using RESTful paradigms
  • Use standard HTTP verbs (GET, POST, PUT, DELETE)

API Endpoints

Format:

/resource/[4-4].ext

Example: Alameda County Restaurant Inspections

https://data.acgov.org/Government/Alameda-County-Restaurants-Inspections/3d5b-2rnz 

... becomes ...

 https://data.acgov.org/resource/3d5b-2rnz.json 

Simple Queries

Equality queries (resource_code == "G") are just GET parameters:

 GET https://data.acgov.org/resource/3d5b-2rnz.json?resource_code=G 

SoQL Queries

More complex queries can be performed using SoQL, our query language:


GET https://data.acgov.org/resource/3d5b-2rnz.json?
$where=activity_date > '2012-11-01'

Customizing output

Tailor payload and retrieve XML:


GET https://data.acgov.org/resource/3d5b-2rnz.xml?
  $where=activity_date > '2012-11-01'
  &$select=activity_date,resource_code,violation_description

<response>
  <row>
  <row _id="20">
    <activity_date>2012-11-06T00:00:00</activity_date>
    <resource_code>G</resource_code>
    <violation_description>...</violation_description>
  </row>
...

Paging & limits

Control how much output you get:


  GET https://data.acgov.org/resource/3d5b-2rnz.json?
    $limit=1

Page through data:


  GET https://data.acgov.org/resource/3d5b-2rnz.json?
    $limit=25
    &$offset=50

Getting Help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment