So you’re ready to try your luck with APIs. Now what? Before implementing your own API at your company, it makes the most sense to use others' APIs. Let’s walk through the basics of how you’d get started using an API.
- Select an API.
First things first, you’ll want to find an API you could incorporate into your business. You might already have your eye on an API, particularly if you’re interested in one of the big wigs like the Facebook API. You might also want to search by cost — you may want to start with a free API before exploring paid APIs, for example.
Once you have an API selected, get your reading glasses on. It’s time to look through the API documentation.
- Get an API key.
As mentioned, an API key is used to identify yourself as a valid client, set access permissions, and record your interactions with the API.
Some APIs make their keys freely available, while others require clients to pay for one. Either way, you’ll most likely need to sign up with the service. You’ll then have a unique identifier assigned to you, which you will include in your calls.
Always key your key private, like you would a password. If your key leaks, a bad actor could make API requests on your behalf. You may be able to void your old key and get a new one if such a breach occurs.
- Review the API documentation.
API Documentation is essentially an instruction manual about how to effectively use and integrate with an API. In addition to providing all the information required to work with the API, like whether or not you need an API key, it usually includes examples and tutorials.
Refer to the documentation for how to get your key, how to send requests, and which resources you can fetch from its server.
It’s hard to understate the importance of good API documentation — a company might offer a powerful API, but if developers can’t quickly learn how to use it, it’s not very valuable
- Write a request to an endpoint.
Next up, you’ll write your first request. The easiest method is to use an HTTP client to help structure and send your requests. You’ll still need to understand and get some information from the API’s documentation, but you won’t need much coding knowledge to be successful.
At this stage, online tutorials can come to the rescue. For example, this YouTube video explains how to use an API to pull location data from Google Maps and then use those coordinates to find nearby photos on Instagram.
- Connect your app.
Now that you understand how to make requests to your API of choice, you can sync your application with it. As a marketer, you don't need to worry about this stage of an API integration. This is the job of a developer, who will employ one or more languages like Python, Java, JavaScript (and NodeJS), PHP, and more.
Chances are, the API you're interacting with is a specific type of API that is considered easier to use than others. These APIs are called REST APIs.
REST APIs
REST APIs conform to the constraints of a software architectural style called “Representational State Transfer” that make the APIs relatively easy to use and discover. REST makes data and functionality available as resources, which are represented by unique URLs. To request a resource via a REST API, like the Open Weather Map API, you just need to provide its URL.
In a typical REST API, a resource will have two URL patterns assigned to it: a plural (to refer to all the resources) and a singular (to specify a single resource). These are also referred to as endpoints. Can you guess why? Because they go at the end of the URL.
Each endpoint is also assigned a list of actions the client can request of the server. So, a plural endpoint may be for listing or creating resources, and the singular endpoint may be for retrieving, updating, and canceling a specific resource. The client would have to include the correct HTTP verb (GET, POST, PUT, DELETE) in its request to tell the server what action to take.
The client and server can use three data formats to pass this information back and forth: