REST WEB SERVICES

What are Web Services?

Web Services are client and server applications that communicate over the World Wide Web's (WWW) Hypertext Transfer Protocol (HTTP). As described by the World Wide Web Consortium (W3C), web services provide a standard means of interoperating between software applications running on a variety of platforms and frameworks.

Web Services can be looked as a code on demand. Just like we call functions and methods, web services can be looked upon as calling a function or method over the internet using some sort of protocols and some agreements.

A web service is a function or method which we can call by sending an HTTP request to a URL, with arguments and the service returns the result back as response.

The biggest advantage of the web services is that it is platform independent.

Introduction to Web Services

Consider the above figure, We can see that the application written in Java can interact with PHP and .net platforms through the web service. Therefore, it is completely platform independent. A web service exposed in the PHP can be consumed by any platform be it java, .net or PHP. This capability of the web service is making it so popular. Therefore, a web service is a language independent way of communication.


Now let us look at one of the most common use case where web services are being used extensively.

Consider the figure below, suppose I have made a new cool application but I do not want to maintain the data of the users, who login to my application, but we want only authenticated users to use the application.

So what should we do? One option is, we can use the web services exposed by some other third party application, to authenticate our incoming users. You must have seen this in many applications, in form of - Sign up using Facebook, Google or other third party apps. Many Websites/Apps use Facebook and Google data, using their web services, to authenticate users.

Therefore, we do not have to maintain any data of the users to authenticate, rather we can now fully concentrate on the content of our application.

The flow of the authentication process will be like this:

  1. 1. User logs into our Application.
  2. 2. We show them two options - either sign in using Facebook or Google.
  3. 3. Enter the Username and Password.
  4. 4. The application will now pass the Username and Password to Google or Facebook server using http request.
  5. 5. The request/response can be in any format. It could be a json/xml or any other media type.
  6. 6. Now if the request is ok, Google or Facebook server will send us the response and accordingly we will authenticate our users to login into the application.

The third party apps, who expose their APIs must provide a proper documentation of all the requests and responses. Checkout this link for the PayPal API to get some idea how documentation is done - https://developer.paypal.com/docs/api/identity/

Introduction