Creating an API for Building Address Site

By peterm, 5 September, 2014

Tags

As part of a campus roll out for providing building addresses to our facilities, I've been working on devleoping a small look up site and API service developed in Drupal.

All campus buildings, parking lots, fields and entities are getting official US Post Office street addresses. This is a second phase of work that follows on the naming of campus roads.

I began by organizing the data into two content types; building_address and mail_stop. The former holds street address, lat, lng info for all entries. The latter is a subset of data based on the campus mail stops. Mail stops are regional based places where campus mail services delivers US and interoffice mail.

The lookup functionality is a simple view with exposed filter for narrowing down the item you're interested in. I used the same technique for both content types.

The API is created using Services and Services Views modules. I created an endpoint called api. Then I created views with exposed filter to allow me to filter on various keys such as nid and tag. The Services module allows for JSON to be delivered by appending a ".json" onto the URL path. This isn't easy to figure out because the documentation isn't very good. I did use the Services Views project page which has a link for a video and some examples.

This pulls back all building addresses in JSON

http://building-address.ucsc.edu/api/ucsc-building-addresses.json

Get a specific building by its nid:

http://building-address.ucsc.edu/api/ucsc-building-addresses.json?nid=5073

Get a set of buildings based on College tag:

http://building-address.ucsc.edu/api/buildings-by-college-tag.json?tag=O... College 

Then there are the 2 main UI's

http://building-address.ucsc.edu/content/ucsc-building-addresses-list

http://building-address.ucsc.edu/mail-stops/list