API

Last Updated Jul 09, 2021

What is an API?

An API, or Application Programming Interface, is a set of rules that define how computers and applications can communicate with each other. If you recall the old switchboards that operators used to field phone calls to their destinations, APIs are a little like that. A client makes a request (also called a query) to an API at an endpoint which it has access to. The API authenticates or validates the request and passes the request to the destination server or program. The server sends a response back, first through the API, which then transfers it back to the client.  

What makes this process so useful? The API provides security by decoupling the consuming application from the infrastructure providing the service. Once an API service and a client exchange authentication keys, they communicate through the API, meaning they don't have full access to each other, but enough information can be passed to get work done.  

APIs also provide a lot of useful services to developers. Imagine if every web shop that wanted to process credit cards had to write their own credit card processing code. It would take forever! Instead, developers can call the PayPal API with their software to securely process credit card payments. APIs are a little bit like external function calls, if you're coming from a desktop programming background.  

How do APIs work in detail?  

A client can issue certain kinds of requests, of which there are four main types:

  • GET - This request reads information from a record in the database
  • PUT- This request changes a record’s information in the database
  • POST - This request creates a new record in the database
  • DELETE - This request removes a record from the database.  

The request is packaged in a JSON (JavaScript Object Notation) file. JSON is ubiquitous because it's lightweight and easy to read. A JSON might look like this:


fetch('https://jsonplaceholder.typicode.com/todos/1')
  .then(response => response.json())
  .then(json => console.log(json))

This request goes to the URL `https://jsonplaceholder.typicode.com/` at the API endpoint `todos/1`. The server receives these instructions at the endpoint, and returns another JSON with the requested information:


{
	"userId": 1,
	"id": 1,
	"title": "delectus aut autem",
	"completed": false
}

This is how information is exchanged in REST APIs (SOAP APIs are a little different). Now imagine all the other requests you could make!

What can I do with APIs?

Here are a few places APIs are used today. Try to visualize the places where data is exchanged between the client and the API.

Conclusion  

APIs are the new nervous system of the Internet. They provide flexibility and power to developers, while making connecting new services as easy as "plugging in" to an interface. In short, APIs let you open up access to your resources while maintaining security and control.

Try Abstract's suite of free API's,
trusted by 100,000+ developers.
Get started