SOAP VS REST API

Web developer must be familiar about difference between SOAP and REST. First thing is that SOAP is complete framework but on the other hand REST is simply a technique (Architectural style; clinet-server). Before learn SOAP and REST we should know about following terminologies.

HTTP:

It is an uni-directional (one way) internet communication protocol over TCP connection. HTTP connection closes when client (browser) receive the response once from server.

  • Client send request to server by HTTP over TCP.
  • HTTP connection open.
  • Server receive the request from client.
  • Server send the response to client.
  • HTTP connection then close.
  • HTTP using REST based communication.

HTTPS:

Extension of HTTP with secure mechanism (SSL).

Web application:

It contains web page(s) serve by server and these pages (user interface – HTML) are run on browser. Server receives the request from client and respond back to client over HTTP. For example: in ASP.Net a action like onclick with ‘runat=server’ will run on it’s web-application server only. So, we can say that web-application events/methods(not web-services) are available only for it’s web-pages. Consumer (end-user) of a web-application is client-browser.

API:

Application Program interface (API) is a apiece of code, works like messenger between two software or systems.

Web-services:

Two different machines/servers/piece of code communicate to each other over web/network is called web-services. So we can say that web-service is an API means that web-service should be usable or intractable for all frameworks/machine/OS/platforms over network. It’s mean web-services must follow the set of rules or standards. There are two types of web-services:

  • SOAP
  • REST (RESTful)


Architectural Style:

A set of rules to develop software. For example: MVC, Client-Server etc…

Object:

  • Object can be any resource like XML.
  • Object can have State (attributes/data)

Serialization:

Conversion of object into byte is called Serialization. So object is serialized before transfer to server-client.

State:

State or Data is same thing.

Stateless:

Server doesn’t store the any information of client. As we discussed communication over HTTP is not continues. Means that connection closes when server respond back to client. After close the connection, server doesn’t retain the information. So we can say that web-application is stateless by nature. To store the state of values, we need state management on server side either we work on ASP.Net or other web servers.

Server-State Management:

On ASP.Net:

  • Session State (Store data globally for single client and stores in file system.
  • Application State (Store and share data globally for all clients ) stores in RAM.
  • ViewState is not a server-state but process by server.

On Apache:

  • HttpSession


REST:

A short form of Representational State Transfer. A web-service which is stateless communication between client to server over HTTP usually (but doesn’t depend on HTTP). There are variety of data format like JSON,XML,CSV and HTML etc.. Following are the constraints or rules for RESTfull API.

  • Client-server environment.
  • Stateless server
  • Cache-able: Respond data can be store on server cache to use it for same request from client (can be same or different client).
  • Layered system -> To improve sociability, provided the extra layer name as load-balancing or provided the shareable caches.
  • Uniform Interface:
    • Resource Identification
    • Resource Manipulation
    • Self-descriptive messages
    • HATEOAS ( Hypermedia As The Engine Of Application State )

What does the mean of Representational?

Let suppose we need to get data of cities from database. So we will use any data adapter to connect with database and then it will return the object. But we just need the representation of data (state) from this object. This representation can be JSON,XML,CSV or other formats.

Object -> Variables -> State -> JSON

REST API can be restricted?

Yes, we can apply the security to authenticate and authorize the user. Like OAuth

What is difference between AJAX call (ASP.Net PageMethods) and REST?

ASP.Net PageMethods is the implementation of REST. PageMethods using for same origin (or need more work for CORS) and REST API using for different origin.


SOAP:

SOAP is a type of web-service protocol. SOAP is a messaging protocol for transporting information between server and client in XML format over HTTP. Remember that SOAP is the application layer (7th layer of the OSI model) level protocol. WSDL describes the method(s), transport details and message format of SOAP web-service. We can get the SOAP web-services description by adding the “?wsdl” at the end of the web-service URL.

https://4allover.com/blog/2018/07/09/soap-webservice-php/

SOAP is uses for both sending and receiving the messages. Here are the basic components of SOAP:

  • Envelop
  • Header
  • Body
  • WSDL (webservice description language) contains the following information about
    • methods
    • parameters
    • return types
  • UDDI

Is SOAP stores the session on server side?

It can be by adding following
[WebMethod (EnableSession=true)] (*this is for ASP.NET)