What is an API?

Understanding REST, GraphQL, and the Evolution of APIs

What are APIs and why do they matter?

Imagine you’re ordering food at a restaurant. You look at the menu, pick your dishes, and tell the waiter your order. The waiter then goes to the kitchen, puts in your order, and brings back the prepared dishes.

The waiter serves as an interface between you and the kitchen. You don’t need to know how the kitchen prepares the food — you simply rely on the waiter to communicate your order and deliver the results.

This is similar to how APIs work in software. The API serves as an interface between two applications. One app makes a request to the API (the order), without needing to know how it’s implemented on the server side. The API then returns the response (the dishes).

For example, a weather app shows forecasts without knowing how weather data is aggregated and analyzed on the back-end. It simply calls the weather API to get the needed results.

So in essence, APIs act as intermediaries that handle communication and data exchange between different applications, abstracting away underlying complexities.

A brief history of API development

APIs have evolved significantly from their early beginnings to the integral role they play today.

In the 1960s and 1970s, APIs were mostly internal, providing connectivity between mainframe systems and custom software within organizations. For example, American Airlines developed an API in the 1960s for its Sabre airline reservation system.

The advent of service-oriented architecture in the 1990s led to the growth of web APIs, also called web services. Companies like eBay (1997), Amazon (2002), PayPal (2000), and Salesforce (2000) offered public APIs for payments, shopping carts, and infrastructure services.

The launch of the Google Maps API in 2005 and the Twitter API in 2006 accelerated the opening of public web APIs. They enabled new mashups and applications built on established platforms. Facebook, YouTube, and others followed this open API model.

The mobile app explosion in the late 2000s further drove API adoption. Uber (2009), Airbnb (2008), and Instagram (2010) relied on APIs to connect mobile apps to back-end services. The client-server separation became a standard pattern.

Today, API-first companies like Twilio (2008), Stripe (2010), and Plaid (2013) are disrupting industries by offering core functionality through APIs rather than traditional applications. The API economy continues to thrive.

Key API concepts and architecture

While APIs come in many forms, there are some common architectural concepts and components that apply to many web-based APIs.

At a high level, APIs allow client applications to access data or functionality from a server via API calls. The client makes requests to the API’s endpoints (URLs) and receives back responses.

For web APIs, requests and responses are typically sent over HTTP or HTTPS. APIs use HTTP request methods like GET, POST, PUT, and DELETE to perform operations. Response codes like 200 OK, 400 Bad Request, and 500 Server Error indicate the request status.

Most modern web APIs return data in lightweight JSON format rather than XML. Developer documentation and SDKs make it easier to integrate with APIs.

Other common API architecture components include:

  • Authentication like API keys to identify applications

  • Rate limiting to prevent abuse

  • Versioning to evolve APIs without breaking changes

  • Caching to improve performance

  • Status monitoring to track uptime

These architectural concepts power the seamless exchange of data between applications through modern web APIs.

Benefits of APIs

There are many benefits to building software and connecting systems using APIs:

  1. Modularity — APIs allow code to be separated into reusable modules with clearly defined interfaces for communication. This breaks down system complexity.

  2. Developer Experience — Well-designed APIs improve developer experience by being easy to integrate with. API documentation and SDKs make APIs more accessible.

  3. Scalability — APIs enable systems to scale by separating front-end and back-end components across servers. Back-ends can be expanded as needed.

  4. Code Reuse — APIs allow code to be reused across multiple platforms. For example, a payment API can be integrated across web, mobile, etc.

  5. Innovation — Public APIs enable new products and services by allowing developers to tap into functionality. The API economy thrives on this ecosystem.

There are also business benefits like additional revenue streams from API monetization and faster time-to-market by building on existing APIs. Overall, APIs done well provide a multitude of architecture and business benefits.

Introduction to REST and GraphQL

There are two leading architectural approaches for designing web APIs — REST and GraphQL.

REST(Representational State Transfer) is one of the most prevalent API architectures. REST APIs rely on standard HTTP methods and status codes to access and manipulate textual data representations.

In a REST API, clients make requests to predefined endpoints at URLs representing individual resources. REST uses HTTP features like caching, content negotiation, and hypermedia controls.

GraphQL is a newer API architecture that was developed to address shortcomings of REST. Instead of accessing pre-set endpoints, GraphQL APIs allow clients to declare and retrieve structured data through a single endpoint using a query language.

In GraphQL, the client requests define the structure of the response rather than the server. This allows retrieving data in flexible shapes optimized for the client. GraphQL also uses a strongly typed schema system.

While REST is better suited for simple use cases, GraphQL improves efficiency for accessing complex nested data and enabling frequent client-driven changes. We’ll dive deeper into the technical comparison in upcoming posts.

This introduces the high-level concepts of REST and GraphQL. Both play major roles in modern API architecture and have their merits depending on your use case.

Summary

APIs have become a critical part of enabling functionality, data access, and connectivity in the software landscape. As usage continues to grow, API architecture has evolved from early internal origins to the wide array of public APIs fueling innovative applications we see today.

Core API architecture concepts like endpoints, HTTP methods, status codes, and authentication power the seamless data exchanges between clients and servers. Benefits like modularity, code reuse, and scalability have made APIs integral to modern software design.

REST and GraphQL have emerged as two leading architectural styles for crafting APIs optimized for different use cases. REST’s simplicity and wide adoption makes it a solid default choice, while GraphQL offers efficiency gains for complex data structures.

Did you find this article valuable?

Support Tony Kipkemboi by becoming a sponsor. Any amount is appreciated!