A web service and an API are two very similar concepts, so it can be difficult to understand the similarities and differences.
Before we get started further explaining web services and APIs, we first need to define a few other terms:
A Web service is a way for two machines to communicate with each other over a network.
A web server running on a computer listens for requests from other computers. When a request from another computer is received, over a network, the Web service returns the requested resources. This resource could be JSON, XML, an HTML file, Images, Audio Files, etc.
An API or Application Programming Interface, is a set of definitions and protocols that allow one application to communicate with another application.
You might be wondering to yourself, APIs and Web services sound like the same thing. It’s a way for two computers to communicate with each other over the internet, right? Well, not quite.
As we mentioned in the section about “What is an API?,” not all APIs are accessible over the internet(a network), while Web Services must always be accessed through a network. That’s the difference right there.
All Web Services are APIs, but not all APIs are Web services.
The short answer? Yes, REST APIs are a type of Web Service APIs.
A REST API is a standardized architecture style for creating a Web Service API. One of the requirements to be a REST API is the utilization of HTTP methods to make a request over a network.
REST was officially defined by computer scientist Roy Fielding in 2000 during his Ph.D. dissertation. It essentially changed the way applications are built. The implementation of the frontend “client” can be built completely independently from the backend “server.”
A REST request from the client to the server usually consists of the following components:
Let’s say that you want to see what your best friend posted on Instagram. To do this, you need to go on the app and open up your friends Instagram page.
In this example, your Instagram app [the client], would make a request to Instagram’s server [the server] to request your friend’s Instagram profile. This request would be a GET request to the /users endpoint and in the parameters of the request your friend’s account ID would be included.
In the same way that you use a GET request to retrieve data, a POST request would be used to create data on a platform. So let’s use the example of posting an image to Instagram. This request would be a POST request to the /media endpoint with a body of the image and parameters with your caption.
The reason REST is so great is that it offers a standardized methodology for making requests to an API. Once you learn one REST API, other REST APIs are going to function in a similar way.
If an API is available over the internet, there is no need to install additional software within your application. You can access the data from any application that is connected to the same network as the API.
With separated development on the client and server, the client code can be updated without affecting the server, and the server code can be updated without affecting the server. This is assuming the changes are developed in a backward-compatible way.
Here is a quick summary of what we covered above.
This article has helped you sort through the differences, ins and outs, and general information you may need to know for an API and Web service.