API Basics from a Beginner

Did you know there is a wealth of information out there that your app can access and use for free (kind of)? All you have to do is program an application that follows RESTful (representational state transfer) conventions. From there, all you need to do is access the proper endpoints of the application programming interface (API) through hypertext transfer protocol methods. Oh, and often times you’ll have to authenticate your request through an ID and token either in your parameters or through your request headers. Sounds simple enough.

What is an API? Truth be told, I don’t quite know even after taking a deep dive into one for a project. I think of it as a magical connection that allows my browser to speak to a database somewhere to access its information. By using the proper incantations, you can summon information from the void of the web. Where and how you access that information is dependent on the API. I’ll be using Triposo’s API as an example.

Here’s an example of an API request I made:

What does all of this mean? It’s easier to digest when you break it up into smaller parts.

This URL is familiar enough. You have the domain address for Triposo’s API and the version number.

This part tells the API which endpoint you want to access. In this case, the endpoint will be their list of points of interests (POI’s) which will be returned in a JSON format.

The question mark is a small, but very important part of the request. It lets the API know that are you going to specify your request based on parameter values. Everything after this will be used to hone in on certain parts of the data that you want.

The first query parameter will be the location, and using Triposo’s documentation, its associated parameter is location_id. Then, the location_id parameter is set “equal to” New_York_City.

The ampersand is the separator between parameter values.

Here, the other query values are being entered. Taking a look at the documentation, the values will tell the API to return us the type of information we want about a particular location such as its name, an intro (description), and images, if there are any. Other things to note is we are getting 10 results back and the POI’s can have any tag label that is NOT “eatingout”.

Lets try out the request.

The API doesn’t like just anyone grabbing info from their database. Often times, you will need to create an account where you will be given an ID and a token. Think of these as a username and password you will use to authenticate your requests.

Here’s an updated request:

Alternatively, we can add in the ID and token as headers in our request.

Account and token are placed in as parameters in the URL or as headers in the request, and now the API will return the information we asked of it.

The JSON object we are returned contains a list of POI’s in New York City with information that we specified in our list of query values. Congratulations! You can now have your application work with this information however you would like.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store