Thursday, August 6, 2015

Web Services Vs API

API and Web service serve as a means of communication.The only difference is that a Web service facilitates interaction between two machines over a network. An API acts as an interface between two different applications so that they can communicate with each other. An API is a method by which the third-party vendors can write programs that interface easily with other programs. 

1. All Web services are APIs but all APIs are not Web services.

2. Web services might not perform all the operations that an API would perform.

3. A Web service uses only three styles of use: SOAP, REST and XML-RPC for communication whereas API may use any style for communication.

4. A Web service always needs a network for its operation whereas an API doesn’t need a network for its operation.

5. An API facilitates interfacing directly with an application whereas.

6. Web service supports data transfer in XML format while API supports XML and JSON.


Web Service:

A Web service is a method of communication between two electronic devices over a network.

  • Web services are small units of code
  • Web services are designed to handle a limited set of tasks
  • Web services use XML based communicating protocols
  • Web services are independent of operating systems
  • Web services are independent of programming languages
  • Web services connect people, systems and devices

How Web service Works:


Types of Web Services:
Web services can be implemented in various ways. Web services can be classified as “Big” web services and “RESTful” web services.

Big WebService(SOAP):
Big web services are based on SOAP standard and often contain a WSDL to describe the interface that the web service offers. The details of the contract may include messages, operations, bindings, and the location of the web service.

Big web services includes architecture to address complex non-functional requirements like transactions, security, addressing, trust, coordination, and also handles asynchronous processing and invocation.

SOAP based Web Services is a great solution when you need:-
Asynchronous Process
Reliability
Stateful Operation

FERSTful Web-services:
RESTful web services are based on the way how our web works. Our very own world wide web (www) – the largest distributed application – is based on an architectural style called REST – Representational State Transfer. REST is neither a standard nor a protocol. It is just an architectural style.

SOAP(Big) Vs Rest:

  • SOAP stands for Simple Object Access Protocol. REST stands for REpresentational State Transfer.
  • SOAP is a XML based messaging protocol and REST is not a protocol but an architectural style.
  • SOAP has a standard specification but there is none for REST.
  • Whole of the web works based on REST style architecture. Consider a shared resource repository and consumers access the resources.
  • Even SOAP based web services can be implemented in RESTful style. REST is a concept that does not tie with any protocols.
  • SOAP is distributed computing style and REST is web style (web is also a distributed computing model).
  • REST messages should be self-contained and should help consumer in controlling the interaction between provider and consumer(example, links in message to decide the next course of action). But SOAP doesn’t has any such requirements.
  • REST does not enforces message format as XML or JSON or etc. But SOAP is XML based message protocol.
  • REST follows stateless model. SOAP has specifications for stateful implementation as well.
  • SOAP is strongly typed, has strict specification for every part of implementation. But REST gives the concept and less restrictive about the implementation.
  • Therefore REST based implementation is simple compared to SOAP and consumer understanding.
  • SOAP uses interfaces and named operations to expose business logic. REST uses (generally) URI and methods like (GET, PUT, POST, DELETE) to expose resources.
  • SOAP has a set of standard specifications. WS-Security is the specification for security in the implementation. It is a detailed standard providing rules for security in application implementation. Like this we have separate specifications for messaging, transactions, etc. Unlike SOAP, REST does not has dedicated concepts for each of these. REST predominantly relies on HTTPS.
In simple we can say below differences:
  • SOAP is a XML-based message protocol, while REST is an architectural style
  • SOAP uses WSDL for communication between consumer and provider, whereas REST just uses XML or JSON to send and receive data
  • SOAP invokes services by calling RPC method, REST just simply calls services via URL path
  • SOAP doesn't return human readable result, whilst REST result is readable with is just plain XML or JSON
  • SOAP is not just over HTTP, it also uses other protocols such as SMTP, FTP, etc, REST is over only HTTP

HTTP Methods:
  • When a HTTP POST request is sent to the URL then the information will be added.
  • When a HTTP PUT request is sent to the URL then the information will  be modified.
  • When a HTTP DELETE request is sent to the URL then the information/record will be deleted.
  • When a HTTP GET request is sent to the URL then the information/record will be fetched.






How Data travel in case of REST and SOAP:


SOAP components:
UDDI: - UDDI (Universal Description, Discovery, and Integration) is an XML-based registry for businesses worldwide to list themselves on the Internet. Its ultimate goal is to streamline online transactions by enabling companies to find one another on the Web and make their systems interoperable for e-commerce.


WSDL: - The Web Services Description Language (WSDL) is an XML-based language used to describe the services a business offers and to provide a way for individuals and other businesses to access those services electronically.


XML: - Extensible Markup Language (XML) is a markup language that defines a set of rules for encoding documents in a format which is both human-readable and machine-readable.


REST Components:
URI: - In computing, a uniform resource identifier (URI) is a string of characters used to identify a name of a resource.
  • URI (uniform resource identifier) identifies a resource (text document, image file, etc)
  • URL (uniform resource locator) is a subset of the URIs that include a network location
  • URN (uniform resource name) is a subset of URIs that include a name within a given space, but no location
enter image description here

WADL: - The Web Application Description Language (WADL) is a machine-readable XML description of HTTP-based web applications (typically REST web services). WADL models the resources provided by a service and the relationships between them.



No comments:

Post a Comment