I’ve published my first Application Programming Interface (API) via the RapidAPI marketplace. I found the process straightforward and well-documented.
Once your API is written and working well (a subject of other articles, not this one), taking it from internal production-ready to published and available-for-sale took just a couple hours. I think I might explore creating several more API’s. Next up: turning Seattlebrief’s Seattle-area news app into an API that other websites and mobile apps could use.
What’s an API?
An Application Programming Interface is a data pipeline and set of protocols that connect two pieces of software. Every time you use Netflix on your phone, for instance, the mobile app calls out to the servers via a set of Internet calls (API’s) to, for instance, fetch your user state (who are you?), fetch the directory of movies based upon your search or browse, and fetch the data stream for the movie itself. The Netflix app does so by using a set of well-documented application calls out to servers.
I like to think of API’s as the LEGO building blocks of today’s mobile and cloud application world. There are API’s for all kinds of things — Zillow home values, Spotify music directory lookups, mapping, advertising, price lookups, travel bookings, and so much more.
Over the years, developers have generally settled upon a set of conventions called REST, which is a specific, simple way to encode an API. REST API’s let developers write code to easily retrieve (GET), update (PUT), add to (POST) or delete (DELETE) information from and to servers.
My First API: New York City Political Precincts
I’ve built many APIs over the past few decades, but this is the first time I’ve decided to publish one on the RapidAPI directory for others to buy. The first one I’ve published involves mapping a street address to a latitude/longitude and relevant political precincts.
In building Alignvote, the voter-candidate matchmaker builder, I needed a way to get from a street address to a list of political districts. The customer, One City Rising New York, wanted voters to be able to enter their street address and see a list of Voters Guide quizzes that are relevant to that specific voter.
So I built an API to take in a street address and, through data lookup, return the list of voting districts that address is part of. I host it on Microsoft’s Azure platform. The API happens to be written in Python, but the specifics of how this API does its magic aren’t particularly relevant for this post.
The API takes a street address (free-form text) as user input, and returns a payload with what City Council District, Congressional District, Assembly District and State Senate District the address is in. It also returns the latitude and longitude for the address.
// example... let's say you enter address=Empire State Building
// the API will return this payload:
{
"formatted": "20 W 34th St., New York, NY 10001, USA",
"coun_dist": 4,
"cong_dist": 12,
"assem_dist": 75,
"st_sen_dist": 28,
"lat": 40.7484405,
"long": -73.98566439999999
}
RapidAPI
Rapidapi.com, is kind of like an App Store for API’s. world’s largest API hub, is used by over five million developers to find, test, and connect to thousands of APIs — all with a single API key. We call these developers that call existing APIs API consumers.
After building my API, I headed on over to the RapidAPI interface and defined the base url of the API, I defined some basic pricing plans, I created the documentation for the endpoints (with some examples), and I told RapidAPI where my “uptime” endpoint (“ping”) is.
Once I linked in my PayPal account (memo to RapidAPI — please use Stripe) — I was all set to publish.
That’s it! Now newspapers, civic organizations and political campaigns which would like to build out some kind of “which voting districts am I in” service for NYC’s 5.3 million eligible voters can more easily and cheaply do so.
You can find the API here: New York City Political Districts API