Web Services vs APIs
There is an analogy that says “All tigers are cats but not all cats are tigers”. Same thing goes with web services and APIs also. All web services are the APIs but not all APIs are web services. Web services and web APIs are commonly taking as same thing or confused with each other. But actually web APIs can be taken as the evolution of web services.
In simple words web services means service that is available over the web. Client invokes web service by sending a request and service sends the response back.There are some standardized XML format to send requests and receive responses.
A web service means exchanging data between applications or systems by using a collection of open protocols and standards on network. Applications can be written in any programming language and running on any platform can use web services to exchange data over computer network.
API stands for Application Programming Interface, and it allows to integrate any two components of an application or any different applications together.
API is a way to specify how two or more software components can interact with each other using some communication protocol. An API acts as an interface between two different applications so that they can communicate with each other. Any communication protocol,can be used by APIs as its not as limited as web services.
In simple words web API is the web based API using for Web applications.A typical Web API specifies how different software components can interact with each other using the HTTP protocol.Here it is not necessary for sender to know what is being processed at other side. It just sends some HTTP commands as GET and when receiver receives the command, it’s up to the receiving system to know what to process and what to send back.
Major types of Web Services
Below are the main components for SOAP web service.
- SOAP (Simple Object Access Protocol)
- UDDI (Universal Description, Discovery and Integration)
- WSDL (Web Services Description Language)
How Does a SOAP Web Service Work?
A SOAP web service provides communication between various applications by using some open standards such as HTML, XML, WSDL, and SOAP.
- The client bundles the requested information into a SOAP message.
- This SOAP message is sent to the web service as the body of an HTTP POST request.
- The web service unpacks the SOAP request and converts it into a command that the application can understand.
- The application processes the information as required and responds with all requested information for that customer.
- Next, the web service packages the response into another SOAP message, which it sends back to the client in response to its HTTP request.
- The client program unpacks the SOAP message to obtain the results of the account registration process.
REST is known as Representational State Transfer. Unlike SOAP-based Web services, there is no official standards for REST web services. In actual REST is an architectural style, and SOAP is a protocol. Web services developed on REST Architecture are known as RESTful web services. REST web services uses HTTP methods to implement the concept of REST architecture.
How Does a REST Web Service Work?
- Resource identification through URI: A RESTful web service exposes a set of resources that identify the targets of the interaction with its clients.
- Uniform interface: Resources are manipulated using a fixed set of operations: PUT, GET, POST, and DELETE. PUT – It creates a new resource.DELETE – It deletes the resource.GET – It retrieves the current state of a resource. POST – It transfers a new state onto a resource.
- Self-descriptive messages: Resources are decoupled from their representation so that their content can be accessed in a variety of formats, such as HTML, XML, plain text, PDF, JPEG, JSON, and others.
- Every interaction with a resource is stateless in REST. Stateful interactions are based on the concept of explicit state transfer. Several techniques are being used to exchange state, such as URI rewriting, cookies, and hidden form fields.
Differences between Web Services and APIs
- Web services provide a standard means of communication between different software applications, running on a variety of platforms and frameworks over the network. An API also acts as an interface between two different applications so that they can communicate with each other but not just over the network.
- A Web service can be seen as an API wrapped in HTTP. An API doesn’t always need to be web based.
- A Web API specifies how software components should interact with each other using the web’s protocol (HTTP). The client doesn’t need to know what procedure to call on the server, in short here we can find a loose coupling. But for web services client need to know the whole contract at server side to call the required service which makes it highly coupled.
- Web services might not perform all the operations that an API can perform.
- A Web service uses only three styles of use: SOAP, REST and XML-RPC for communication whereas API may use any style for communication.
- With web services the amount of work that has to be done by the consumers and providers to package and unpackage the data is quite high. For API scenario typically requires far less work for the same. This is one reason why web APIs are great for information transfer on mobile devices and tablets compared to web services.
Common things in Web Services and APIs
- Both web APIs and web services provides a way of communication between consumers and providers.
- Both support XML-based request/response data transfers, but JSON is more commonly used by web APIs.
- Web services are a service from one application to another, communicating over the network. APIs are software-to-software interfaces with an abstract set of instructions for accessing web-based applications.
- Whatever we want to be done by a web API can be done by a web service also. That is why web services can be seen as predecessors in the evolution of web integration methodologies.