Working with APIs for Non-Coders Recap

Jul 14, 2014

In a recent event titled: “Intro to APIs: Working with URLs, JSON, APIs, and Open Data—Without Writing Any Code,” federal practitioners and supporters interested in open data attended an in-person workshop, led by Eric Mill, a key developer on GSA’s 18f team. This event was especially targeted to non-developers and explored the basics of APIs, using the Congress API, offered by the Sunlight Foundation, as an example. The purpose of the event was to showcase that anybody of any skill level can understand and use APIs without any coding knowledge! Below are some takeaways for those who weren’t able to attend the event.

Understanding the anatomy of a URL

In one sense, APIs are just URLs that lead to data instead of a Web page. In order to explore an API, we need to understand the breakdown of a URL. As an example, take a look at the following URL.

https://www.flickr.com/search/?sort=relevance&text=ukraine

https is the protocol or set of rules used in the communication between the browser and web server.

flickr.com is the domain name. Think of this as the “web address.”

/search/ is a path – a folder in the root folder.

?sort=relevance&text=ukraine is information you are sending to the server.

APIs aren’t complicated

As stated above, APIs are just URLs that lead you to data. There are many formats used to create an API, but JSON is most common these days. There are several reasons for this, including “cleaner” data, greater efficiency, and scalability. One way JSON accomplishes this is by using arrays. Arrays allow values to be compacted, or in other words, arrays are a way of holding data that would be difficult in a two dimensional grid.

You sometimes need an API key to access some APIs. It is usually a quick registration process to obtain one and there should be clear directions for how to do this. The documentation also includes a description and details on what data you can access through the API as well as other information useful to navigating around the API.

Lastly, by adding certain paths or values in your URL, you can narrow down the API to give you just the data fields you want to access.

The URL below for the Congress API has the same features as the Flickr URL mentioned above.

An image of the very, very long color-coded URL to access the Congress API

Entering this URL into a browser then returns information specific to the request:

425 x 620 Nomination code API

Simplify your tabular data by converting your JSON file into a CSV

You can use this tool to convert your JSON files into CSV (simply copy and paste the JSON data into the text box). The purpose of this is to make it easier for you to look at the data. CSV stands for Comma Separated Values and a CSV file stores your tabular data in plain-text that is easily viewed as a spreadsheet.

Conclusion

There’s a lot you can do with APIs and you don’t have to be a developer or a coder to do so. Check out this blog post where a non-developer used the Sunlight API to make a Twitter bot that automatically tweets out Happy Birthday to our Congressmen.

All it takes is a little courage and determination!Editor’s note: GSA will be hosting this session again in the future, so everyone will have a chance to take this class and others like it.

Originally posted by Zeshan Khan on Jul 14, 2014
Jul 14, 2014