A beginner's guide to Web Service v API.

A beginner's guide to Web Service v API.

·

6 min read

1. Web Service.

A web service is nothing but two machines communicating with each other over a network is called a web service. Well our internet itself is based upon web service. A webserver(Backend code capable of handling HTTP Requests and Responses) running on a computer listens to the requests that come from the client-side computer(user side). When the request is received by the web server, it responds to the client, depending upon the request a web server can make the response in any of the following data forms which are JSON, XML, HTML, Image file, video file, etc. And if the client makes an invalid or bad request then the webserver responds with an error message. Our internet can be considered as a web service. As it is all about a user making a request and getting back a response from the web server over a network.

Web Server.png

Now as that is done let's move on with types of web services in brief.

Here mainly two types of web services,

  1. RESTful Web Service.
  2. SOAP Web Service.

RESTful: It stands for REpresentational State transfer and it is developed by Roy Thomas Fielding the creator of HTTP. It uses the concepts of HTTP to define itself and hence this makes Web Services more simple and effective which is the goal of RESTful. As we know now REST is defined upon HTTP, so along with HTTP; REST is also a stateless service. This is because each request from the client is executed independently without any reference to the previous requests made by the same client. Hence to maintain a state or session between client and server, we have to make use of Cookies, but that's not the goal for this article so let us keep it for another day.

SOAP: REST is mostly an architectural approach to building web services while SOAP is a way to allow the exchange of data only in XML format strictly. It's is an acronym for Simple Object Access Protocol. It defines the data transfer between client and server in strictly XML format. There is not a comparison to make between SOAP and REST. SOAP is also a way of building web services and Web Service Definition Language (WSDL) is used for the request and response in XML.

Now as you have got a thorough understanding of web service, let’s dive into API.

2. API.

Well, you might have heard the word 'API' like a gazillion of times, but never actually get to know it in detail so let's dive into what is an 'API'. The acronym 'API' stands for Application Programming Interface, in other words, it is a way for big tech companies to share data and functionality of their existing product to third party users or developers and other internal departments within their company. Now, this makes it possible for different services and products to communicate and take advantage of each other's data and functionality through a documented interface (set of rules to access data and functionality). The implementation of an API, that developer don’t need to know; they just have to simply make use of documented rules to communicate with the service. Okay, this might seem a lot for many of the readers, but let us understand it in simpler words.

Now that we have gone through the industry definition of an API, let's hear it in a more real-life application manner and some examples.

Let us assume that you are working on a project, and the main aim of the project is to build an app like social media where users can sign up, sign out, add a post(Image or Video), delete, and edit the post very similar to Facebook. Now you wish to add a side functionality to your project like other users can view the location of an image or video taken at a place by a particular user, on a service like google maps. You would normally think that can be done by simply visiting Google maps itself. But suppose you do not want the user to leave your application for others, and you want to show the maps like structure and the location on your application itself. Now the question arises whether to write the entire code and bring all the data for displaying any location as google maps do and which is near to rocket science?

Well here comes API into the picture, so along with google launching the Maps, they also launched a service called Maps API for the other companies and developers to take all the advantages of the functionality and data, Maps Provide. Similarly, other companies also launch the APIs of their products, like Twitter API and YouTube API.

Now coming back to the topic, what you can do is simply make use of the API provided by Google to your project, and how to make use of it Is clearly defined by the official documentation of Google Maps API, which is another whole topic for some other day!

Another example is a third-party application that allows users to sign up and sign in with Google, Apple, GitHub, and a variety of other service accounts; this is one of the most popular uses of API that we as consumers encounter in our daily lives.

API.png

Now, let's discuss what an API brings to the table?

In the software industry around the globe, there is always a best practice called ' Code Reusability ', and that's what an API brings to the table. API integration is exactly like reusing a code that someone has already written for us and taking all its leverages. Hence, integrating an API can help maintain the code size, and as it’s already been written which makes developers only left with is follow the documentation.

Now you might have got a clear idea about what is an API, but you still might be wondering what the difference is between an API and a Web service is, so let's get that.

3. The Difference.

This is probably going to be the biggest takeaway from this article,

  • In order to answer this one, a web service relying on a computer or can even be called the server can make itself available to everyone across the internet. While the API is only available to the computer which is aware of proper connection methods or credentials to access the service, and not across the whole internet.
  • A web service is software also made up of open-source protocols and standards, whereas API is just a software interface for products to communicate with services, or in the more simple way two applications to connect, share functionality and data.
  • The main difference to notice is 'All web services are APIs, but all APIs are not web services' Meaning web services are a subset of API. To elaborate more, web services and API have the same architecture of requests and responses between client and server, but not everyone can simply access the APIs like a web service, an entity needs to have a proper set of instructions to connect with an API whereas all a web server requires is the internet. Hence Web Services falls under the concept of APIs.
  • Web services can be invoked by any entity having the access to the internet, while interaction with API is only done by software engineers or developers.

So wrapping up, and I hope that this has made a more clear understanding, I will be coming up with more topics. Till then next time!

You can follow me on Twitter if you like, Ciao!