Learning APIs for the first time is tricky — not only are there many technical terms, but these terms often overlap in meaning. This, understandably, causes some confusion, since some words mean close to, but not exactly, the same thing.
One example of this is the terms “web service” and “API.” Both technologies are vital to modern software architecture, and you’ll likely see them pop up frequently if you work in the space.
However, it’s important to understand what distinguishes web services from APIs, since they have different uses depending on the needs of your software. In this guide, we’ll briefly review what APIs and web services are individually, then compare the two and highlight their differences.
What is an API?
An application programming interface, or API for short, is a software component that enables two otherwise unrelated applications to communicate with each other. An API consists of standardized rules and functions that determine what data may be taken from or modified within an application, and how this process occurs.
APIs are utilized for software integrations, since APIs expose some of an application’s inner data and functionality to be used by developers. This is what makes an APIs an “interface” — it acts like an interface where you can request data from an otherwise closed-off application.
Today, APIs are behind most integrations we see over the internet. APIs that send data over the internet are called web APIs. As an example, consider weather apps. While we use these quite often, the weather apps themselves are not generating the weather data. Rather, they request this weather data from a weather API. The weather API connects the software that gathers and stores weather data with the application that tells you it’s going to rain tomorrow (sorry).
Software developers may follow one of several architectures to build an API, the most popular being Representational State Transfer (REST) and Simple Object Access Protocol (SOAP) — learn more about REST and how it differs from SOAP here. Without going too in-depth, API architectures standardize APIs, ensuring they can communicate using common languages and procedures.
APIs may be open, meaning free and publicly available, or private, meaning they may only be accessed by approved developers (and likely for a price). Also, a company may develop its own internal APIs to connect its systems, such as in a microservice.
What is a web service?
Broadly speaking, a web service is a resource that is available over the internet, one which provides some functionality that other applications can use. This functionality might include payment processing, logins, and database storage.
According to the World Wide Web Consortium (W3C), web services “provide a standard means of interoperating between different software applications, running on a variety of platforms and/or frameworks. Web services are characterized by their great interoperability and extensibility, as well as their machine-processable descriptions thanks to the use of XML. They can be combined in a loosely coupled way in order to achieve complex operations."
In other words, web services allow software applications to work together, even if they’re built in different ways. And, by utilizing different web services, an application can combine many different functions without having to code all of them in-house.
In this way, web services are central to Service Oriented Architecture (SOA). In basic terms, SOA divides a software function’s applications into modular services connected over a network. SOA enables the reuse of the same function across many applications, without the need to re-code it.
Web services require a network in order to work together, and this networked communication is usually achieved with SOAP. SOAP encodes data in XML, a common markup language for storing and transferring information, and sends it via HTTP, which is the same protocol that delivers web pages from web servers to browsers. To interact with a web service, an application sends an XML request to the service, and the service replies with a response also formatted in XML.
It should be noted that web services can also follow REST principles, though SOAP is the more common architecture among web services.
Web Services vs. APIs
Though APIs and web services can both facilitate data transfers between applications over the internet, they are not the same, and the terms should not be used interchangeably in every case. The key distinction is that web services are a type of API: All web services are APIs, but not all APIs are web services.
“API” is the broader category because, by definition, an API is any software component that acts as an intermediary between two otherwise disconnected applications.
Since web services are designed to share data with other disconnected applications, this qualifies them as APIs. However, a web service is just one way to implement an API. Let’s review what makes a web service different from other types of APIs in use today.
Communication Over a Network
Web services must communicate over a network, a system that connects two or more software applications located on different machines. Usually, this network is the internet.
While many APIs utilize networks, they’re not required to — APIs may function offline as well. For example, two apps on the same computer may integrate via APIs. Data is still being transferred, just not over a network.
APIs can be divided into types based on their scope of users. Some APIs allow any developer to mess around with them with limited oversight, while APIs are restricted to paid clients. Web services fall under the latter category — usually, only approved partners may utilize a web service. This gives web service owners more control over who accesses their data and functions, and how these are used.
Architecture and Format
An API may adhere to one of a variety of designs, including REST, SOAP, XML-RPC, or JSON-RPC. Web services, on the other hand, typically stick to SOAP. This is because the SOAP protocol tends to be more secure and better at preserving data integrity than other API designs.
The main trade-off is that SOAP is more strict in its requirements than RESTful design, making it more code-heavy and process-intensive. For this reason, a web service may incorporate principles from REST or XML-RPC. Still, it’s commonly agreed that SOAP is the go-to protocol.
APIs and Web Services: Similar, but Not Identical
To summarize, APIs and web services are two technologies for transferring data between separate software applications. API is an interface that exposes data of an application to outside software, whereas web applications are one type of API with stricter requirements. These requirements include communicating over a network, using SOAP as the primary communication protocol, and generally allowing less access from the public.
While these definitions might seem quite nuanced, it’s important to understand the subtle but important distinctions between web technologies. Armed with this knowledge, you'll be well-equipped for discussions with developers and have a better understanding of your product’s integrations.
Originally published Sep 20, 2021 7:00:00 AM, updated September 20 2021