Web services is a technology that enables interaction between any two applications. In order to get a clear picture look into the example below

Consider a bus booking site. When the user selects a bus and input all the information, he has to make the payment and for that, the site requires a user to select a mode of payment. If the user selects CREDIT card as the mode of payment then a user has to input all the credit card details. Now, these details cannot be authenticated by the bus booking site, it has to request the bank to authenticate the details provided by the user. But how will it interact with the bank because the bank application can be developed in any technology? The bus booking site has no control over which technology the bank application has been developed.

That’s where web services come into the picture.

It makes the interaction between two applications possible. It accomplishes by serving the data in the standard format such as XML or JSON.

In our example, the bus booking site will send all the CREDIT card related information. The bank application will then authenticate the credentials and then return an appropriate response to the bus booking site.

Why do we use web services?

Web services are a way to expose a functionality of your website to the outside world so that other applications can use it. Moreover, if you want some data from your website to be visible to other devices like android or ios then you can expose this data using web services and it can be consumed in android or ios or windows or any other platform for that matter.

A web service can be used by any application. So basically you write code only once and it can be reused across multiple applications by calling that web service.