APIs are the workhorse of modern web development. They put the "A" in JAMstack. And knowing how to work with them is a requirement for a career in frontend web development.
API stands for Application Programming Interface. An API's function is to relay information, requests, and responses between two or more programs or machines.
An example of an API you might need to use one day is Stripe. Stripe is a software company that creates software that processes online payments. They have developed the Stripe API, which allows any developer on the planet to interact with Stripe's payment processing software.
By using the Stripe API, you can add payment processing functionality to a website without possessing that specific area of software and banking expertise.
Sometimes an API simply provides access to a third-party database. An example of this would be the Open EAN/GTIN Database API, which allows you to access product information based on barcode details.
Some APIs allow you to add to a database. An example of this is the Twitter API, which allows you to add Twitter posts to your feed via the API.
The core similarity is that an API allows you to interact with software that you did not write and machines and data that you do not own.
In this tutorial we are focusing on web service APIs. These are APIs that are designed to pass information between machines over networks like the internet, but there can also be local APIs. can be structured differently, which affects how you interact with, or consume, the API. So it's important to know about the common types.
By far the most common since 2000, the REST, or RESTful, API is one that conforms to the constraints of the REST architectural style and allows for interaction with RESTful web services. REST stands for representational state transfer. By working within a set of architectural constraints, the RESTful APIs provide consistency to all developers. The reason RESTful APIs are so common is that they offer a standardized methodology for making requests to an API. So once a developer works with one REST API, other REST APIs are going to function in a similar way. If you want a career in frontend web development, learn to master consuming RESTful APIs.
An emerging API type, GraphQL API data is presented as a schema, which can be viewed by developers within the GraphiQL development environment. Frontend developers use the GraphQL query language to consume the data, providing the frontend, or client, with only the necessary data. Since this is an emerging technology, it is important to learn to consume GraphQL APIs.
SOAP APIs are an older format, and you might encounter them when working on a legacy project. This tutorial will not cover SOAP APIs, though there are plenty of resources available online should you run into a SOAP API in your career.
These API types are older. Both follow a strict format that developers can rely on. One uses XML, and the other uses JSON data.
Some APIs are public. Some APIs require a developer key, which functions as an authorization protocol allowing access. These keys are acquired when registering with the API provider.
For example, Stripe requires a developer key so they know who is transferring money! Also, since some APIs charge for use, this is a way of tracking usage.
As a rule, it's highly recommended to keep your keys private. If someone else uses your key, you could get charged for their activity! Here is a good article on keeping your API keys secure: Best Practices For Securely Storing API Keys
Follow for future posts on how to consume RESTful and GraphQL APIs.