Becoming a developer is challenging because not only does it test your brain and coding knowledge, but it tests you personality too. There are days where you get it and days where you just don’t and you ask yourself, “am I even smart enough to be pursuing this? I should probably just give up.” We have all been there and you’re lying if you say you haven’t.
In light of my own past issues of not being able to find resources explaining this stuff in plain English, I have teamed up with experienced iOS developer John Martin (@martinsoft) to bring you a series of WTF articles discussing subjects that maybe you’ve just been pretending to know in order to get by.
The first in this series is Application Programming Interface, a.k.a. API.
A: In your own watered-down digestible words, wtf is an API?
J: Let’s start with the word interface. An interface is a piece of software that an app or system provides so that other “things” can interact with it in some way:
- A user interface lets users interact with software. This interface is usually visual, presented as windows, icons and other controls that are easy for users to make sense of and interact with.
An API is a programming interface — something that developers can use to interact with software using code. They’re basically a set of functions, data types and rules that say: “these are the things I can do for your code; this is how I expect your code to send requests to me; and this is what I will give you back”.
APIs are used everywhere in software development:
- Whenever you use a library or framework, you’re using an API.
- Operating systems are made up of layers of APIs that make it possible for all of the different applications and services to run on top of it.
- Web-based APIs work over a network using web technologies (HTTP).
A: What benefits do we get from APIs?
J: APIs “open up” the functionality and data from one piece of software so that it can be used by another piece of software.
- They save us time by allowing software to be reused and connected together — like building blocks for code.
- They make our lives easier by hiding detail. As a developer you don’t need to know how an application or library works internally — all you need to know is how to interact with it over the API.
- They also mean that applications can be updated or replaced entirely, as long as the API stays the same.
A: If an API didn’t exist, what issues would that cause? Why do we NEED APIs?
J: Without APIs, software development would become almost impossible:
- we’d be unable to reuse functionality that someone else has already written.
- we’d be unable to share data between different apps / platforms.
- developers would have to write everything themselves, or know the inner workings of someone else’s code in order to use it.
- software would be difficult to replace or upgrade, because anything that was dependent on it would also potentially need to be replaced or updated.
We need APIs to make us more productive as developers. As an example, let’s say you wanted to build an app that had a screen showing a map of your current location:
Without some sort of maps API (like Google Maps) you’d have to:
- build your own mapping platform
- provide all the mapping data
- figure out how to draw the map
- figure out how to find the part of the map that corresponds to the current location
- … and lots more 😅
With a mapping API, you get all that functionality “for free” 🎉.
Someone’s already done the hard work of figuring out how to draw maps. You can reuse their work, save time and focus on building the things that make your software unique.
A: How would you recommend a new developer get familiar with APIs?
J: For web-based APIs, the first step is becoming familiar with web-based technologies and concepts. Some of the key ones are:
- Web-based APIs use the same protocol as the rest of the web, so understanding the basics of how HTTP works is a great first step.
- This is the term given to the different URLs that make up the API.
- e.g: http://myserver/customers might be the customer-management endpoint of an API.
- To use a web API, a developer writes code to send an HTTP request to an endpoint hosted on some server, and then takes action based on the response that comes back.
- To make them easier to use (and debug) the data sent in the HTTP request/response is usually coded in a form that’s easy for both machines and developers to understand.
- This is usually JSON because it’s easy to use and widely supported. (Sometimes XML might also be used).
- REST is a style of web API which uses the type (“method”) of HTTP request to determine the operation that should be performed.
- E.g. a “customer” endpoint might support GET (fetching a customer), PUT (create/update), and DELETE types of HTTP request.
Once you’re comfortable with these concepts, you can get to know a particular API by starting with the documentation, and then experimenting with it either through code / in a browser / or by using something like Postman to send requests to the API and see what comes back.
- An API is a software interface for developers.
- They allow different pieces of software to talk to each other.
- This means one system can use the data and functionality of another system, without having to know how the other system works internally.
- They allow software to become reusable and interchangeable (we can replace or update software provided the API stays the same).
- Web-based APIs are accessible over a network using HTTP.