Many beginners who start development, especially back end, get confused with terms like APIs, Microservices, Web services, endpoints, etc. The aim of this article is to describe what these terms are with a simple example. Please note that the example given here is just a demo.
Microservice Architecture is a way of designing the structure of an application. Microservices are independently deployable services that together make the application. The architecture of an application can be in such a way that it can have multiple independent microservices that can function together. Splitting the application into microservices makes the maintenance of the application easier. It is also helpful in reducing the complexity of the application. Proper microservice architecture reduces complexity, increases flexibility, increases reusability as compared to a monolithic architecture.
API(Application Programming Interface)
According to NIST definition, an API is,
A system access point or library function that has a well-defined syntax and is accessible from application programs or user code to provide well-defined functionality.
API provides a well-defined set of protocols, routines, and rules for a system so that another system can communicate with it. An API specifies how software components should interact. Documentation on how to use the API should be available.
Web API is an API limited to web applications. Web API is the type of API that provides an interface for web servers or web browsers to communicate. A server-side web API can have one or more endpoints to which requests can be send following a set of protocols and rules so that response is received. REST and SOAP are the two architectural styles of server-side APIs.
Web service is a system that listens on a port to requests from another system in the same network/web, analyze it and provide a response. The request and response are made as web documents JSON/XML/HTML. Web services follow protocol such as HTTP/HTTPS while sending and receiving data. The term web service is used exclusively while building a system that communicates over a network/world wide web.
All web services are APIs but not all APIS are web services.
Web services are exclusive for web communication. APIs can be built for non-web purposes too. APIS and web services can be a part of microservice architecture and can be independent. So APIs and Web Services can be Microservices.
Consider a banking application as given in the diagram below
A single monolithic service does all the backend works including authentication, authorization, profile handling, account info. The front end can be written in angular/React and backend using Node.js environment. The backend service can have multiple GET/POST/PUT/DELETE routes which will handle all the operations. Note that this might not be the ideal architecture/requirement for building a banking application. This is just an example.
Now, to adopt a Microservices architecture, this huge service is split into individual Microservices, each independent and communicating with each other. Each of these microservice has routes and allow GET/POST/PUT/DELETE HTTP requests in JSON format and provide a response in JSON format(REST API).
Thus conceptually all these microservices are WEB APIs as they are interfaces for two systems to communicate, in this case with the business logic and database. All these microservices are for web applications and are connected via a network/internet making them Web services.
All APIs might not be Microservices depending on the architecture.
All Webservices are WEB APIs
All APIs are not Web services
For learning in detail about microservices architecture
Production‑Ready Microservices-Building Standardized Systems Book by Susan J. Fowler
If there are any corrections or doubts regarding the contents of this article, please don’t hesitate to comment in the box below.