Basics of API and Web-Service

Soumya Kar
3 min readAug 7, 2021

--

What is API?

Full form of API is Application Programming Interface.

The term API is very common now days and we are using API in our day to day life. When we use Facebook or Gmail to sign up for anything we use API of facebook or Gmail ; When we book tickets in Make My Trip or Goibibo application, then we use API; We see embedded twitter or Google map in many application to display recent tweet or to show the location respectively, there we use API of twitter or Google map

So now the question is coming what exactly an API is. It is nothing but a medium through which two applications can communicate where these two applications can be built in two different/same technologies. If the communication is happening with the use network/internet then it’s termed as Web Service else it is termed as API.

An API is a set of codes which allows two or more than two applications to communicate each other and provide a result to end users or to another API

An API can call another API or Output of an API can be input for another API

Why we need API:

  • Let say our app wants to access another app’s data or functionality. For example, we want to access recent twitter tweets to display in our application. It won’t be possible without the help of API which will be given by Twitter because twitter will not give/share us their code of twitter. So they have created many API to get recent tweet, to create tweet, to update tweet, to delete tweet. Using get tweet API, we can show these tweets in our applications.
  • Another example: when working with Selenium, we need to access Gmail for verification of some emails. For that we don’t need to automate Gmail to verify the email, we can use Gmail API to get email and verify the contents.

Difference between API and Web service:

  • API and Web service serve as a means of communication. All Web Services are APIs but all APIs are not Web Services. So API is super set of Web service or we can say web service is a type of API
  • A web service always needs a network for its operation (think make my trip example where make my trip is using Restful web service of different airlines to get data for flight) where API does not need a network for its operation. An API exactly defines the methods for one software program to interact with another. When this action involves sending data over a network, web service comes into the picture. An API generally involves calling functions from within a software program
  • A web service uses only three styles of use: SOAP, REST and XML-RPC for communication whereas an API may use any style for communication.
  • An API facilities interacting directly with an application whereas a Web service interacts two machines or application over a network.
  • Web service might not perform all the operation that API would perform.

Next question is coming when API uses network and when it doesn’t:

  • First case API: There is a big application which has many components. A component will communicate to other component to get data or provide data. For example: Login component of XYZ application needs to communicate with Profile component to get user’s data. Here the components will communicate to each other through API. It does not require any network to communicate. API can be exposed through local files (such as a JAR file in Java Program, .H file in c/c++ programs, etc.) to allow two local applications to communicate with each other. This does not require a network as the two applications are communicating within a single device.
  • Second case web service: When we use facebook or Gmail to sign up for any app we use API of facebook or Gmail. Here App and facebook are communicating through an API as it is happening over network so we call it as Web Service instead of API.

--

--

Soumya Kar

Working as Test Automation Engineer, having 8 years of experience in Software Testing