rest api vs soap api code example

Example 1: soap vs rest

RESTful supports JSON, XML,
	SOAP supports only XML
REST is faster than SOAP based web services
	SOAP is more secure
REST allows a greater variety of data formats,
	SOAP only allows XML.
    
    1) SOAP
- Communication happens using XML only
- Request is sent to SOAP methods
- Documentation is in WSDL (Wizdal)
- Heavy, more secure, more stable
- getting less popular
    2) REST API
- Communication happens using Json, XML
- Requests are sent to API methods/urls using
- Communication happens in HTTP(Internet)
- Lightweight, stable
- Easy to develop and automate
- very popular

Example 2: soap vs rest

RESTful:
	- is architectural style
	- stateless
	- requires HTTP
	- supports JSON, XML, HTML, CSV, plain text
	- easy documentation and easy to understand
	- efficient and faster
	- less bandwidth
	- less secure
	- Uses JAX-RS API for security

SOAP: 
	- ss XML based protocol itself
	- State or stateless
	- Can work with HTTP, SMPT(Simple Mailing Transfer Protocol), 
    FTP(File Transfer Protocol)
	- Only works with XML
	- Documentation is complex and hard to understand  
	- Slower than REST
	- More secure
	- Uses JAX-WS API for security
	- Platform and programming language independent

REST-Assured library helps us in testing our RESTful APIs easily. 
It integrates seamlessly with TestNG and JUnit. JSON Path and XML Path 
allows us to easily parse the response data and test specific elements. 
Since it uses Hamcrest matchers, there are many options to match actual 
result with expected data.

Example 3: difference between soap and rest api

RESTful supports JSON, XML,
	SOAP supports only XML
REST is faster than SOAP based web services
	SOAP is more secure
REST allows a greater variety of data formats,
	SOAP only allows XML.
    
    1) SOAP
- Communication happens using XML only
- Request is sent to SOAP methods
- Documentation is in WSDL (Wizdal)
- Heavy, more secure, more stable
- getting less popular
    2) REST API
- Communication happens using Json, XML
- Requests are sent to API methods/urls using
- Communication happens in HTTP(Internet)
- Lightweight, stable
- Easy to develop and automate
- very popular

Example 4: rest api vs soap api

* REST (REpresentational State Transfer):
	- It is an architecture style. It tells how to build web service. It is a convention not a protocol. 
	- Stateless ==> The server does not store any state (data) about the client session. Client is responsible.
	- Uses only HTTP
	- Uses mostly JSON but can also use XML, HTML, CSV, YAML, plain text, etc.
	- Documentation is easy to understand
	- More efficient and faster
- It requires less bandwidth to transfer message than SOAP. 
	- Less secure
 	- REST based web services use JAX-RS java API.

REST has better performance and scalability. REST reads can be cached, SOAP based reads cannot be cached.
REST services are meant to be called by the client-side application and not the end user directly.
You transfer the state around instead of having the server store it, this makes REST services scalable.
REST allows better support for browser clients due to its support for JSON.
JAX-RS stands for “Java API for RESTful Web Services”. JAX-RS API enables developers to rapidly build Web applications in Java according to the REST architectural pattern.
RESTful APIs are built based on some conventions not rules or protocol. So, conventions are “SHOULD DO” whereas protocols are “MUST DO”.

* SOAP (Simple Object Access Protocol):
	- It is an XML based message protocol 
	- State or Stateless
	- Language, platform and transport independent
- Can use SMTP (Simple Mailing Transfer Protocol), FTP (File Transfer Protocol) or HTTP
	- Uses only XML
	- Documentation is complex and hard to understand
	- Slower than REST
	- More secure
	- SOAP based web services use JAX-WS Java API
- JAX-WS stands for “Java API for XML Web Services”

- SOAP is like XML based message protocol with strictly defined message structure, authorization mechanism and required documentation. It looks like HTML because both use XML format. 
- Learning SOAP is much harder than REST because SOAP requires specific message structure. 
- SOAP more secure, more stable but heavier(slower). It requires more bandwidth to transfer message than REST. 
- SOAP message request is processed slower as compared to REST and it does not use web caching mechanism.
- While SOAP supports SSL (just like REST) it also supports WS-Security which adds some enterprise security features.

Tags:

Misc Example