Tuesday, 24 May 2022

REST Service and SOAP Service

Rest Service

Rest stands for Representational State Transfer. 

It is an architecture that defines some guidelines to develop rest services. These guidelines will be followed globally. Rest Services can be implemented by JAVA, DOT NET, SOA, OSB, OIC, MuleSoft, and many more ways. 

Rest services follow the client-server model and it uses HTTP protocol and its corresponding methods to execute the certain request


Standards

  • Rest services follow the client-server model which consists of clients, servers, and resources with requests managed through HTTP methods.
  • Rest services follow stateless client-server communication meaning it does not store the client state and each request is separate and unconnected
  • Rest services also follow the caching to minimize the server calls for the same type of repeated requests


Every content in the Rest architecture is considered as a resource like HTML pages, text files, images, etc., and every resource is identified by URI. You can imagine a resource as an object.

  • URI stands for Uniform Resource Identifier which is used for identifying each resource and identifies resource either by its name or location. URI may or may not be accessible over the network
  • When it identifies a resource with location then it is also known as a URL (Uniform Resource Location) and with the URL you can access the resources over the network.
  • When it identifies a resource with the name then it is also known as the  URN (Uniform Resource Name). It is used to identify the resource, not the location. You can consider it as a namespace that avoids name conflicts 

URI format is 

<Protocol>://<Host:port>/<resource-path>?queryParams

Where

Protocol: HTTP

Hostname identifies the host that holds the resource. like www.google.com

Port: For HTTPS port is 443 

resource path: is the relative URL and it identifies the specific resource in the host that the web client wants to access. it optionally contains templates params as well

query Params: It is basically key-value pairs and it is used as where clause 


HTTP Request/Response contains 

1. Header --> It contains metadata like request authorization, content type, Accept, and other metadata associated with  API Request and response

2. Template Parameter --> It is the part of the URL path and it is used to identify a specific resource within a collection based on a unique id such as a customer identified by customer ID. A URL can have multiple path parameters or template parameters and each template parameter is denoted by curly braces{}.

ex. https://hostname:port/resourcepatch/{template-parameter}

3. Query parameter --> It is added at the end of the URL and it is used to perform actions like filtering the collection. It is in the key-value pair and added appended after the question mark ?.

Ex. https://hostname:port/resourcepatch/{template-parameter}?fname=vivek&lname=kumar

Body --> It contains the request and response body which is actually processing data. It can be in different formats like HTML, XML, JSON, text, etc.


HTTP Methods are also known as HTTP verbs. It specified what action will be performed on the resource

Get --> To fetch one or more resources

Post --> To create a new resource

Put --> To update a resource(As many as fields)

Patch -->Partial update to a resource (1 or 2 or 3 fields)

Delete --> To delete the resource

Some more are Options, Header, Connect, Trace, Move, etc.

Post, Put, Get and Delete corresponds to Create, Update, Retrieve and Delete operations and are also known as CURD operations 

What is Idempotent and which HTTP methods are idempotents

An idempotent HTTP method is an http method than can be called many times without different outcomes.

By Default Get, Put, Delete and Head are idempotent methods and a post is a non-idempotent method

How to secure Rest services

1. HTTPS --> Use the HTTPS protocol to secure the transaction over the internet

2. never expose the user name and password and email id and any other sensitive data in the query parameter

3. OAuth or Basic Authentication:  Incorporate an authentication and authorization on the rest API to secure it


SOAP Service

SOAP stands for Simple Object Access Protocol

SOAP is the protocol for exchanging structured information meaning SOAP wrap the message in the envelope and its structure will be like below



SOAP is XML-based. Below are the sections

Header: It contains the header information

Body: It contains the actual body

Fault: It contains the fault messages

Features

Web Service Security (WS-Security): It enables SOAP services to secure messages

WS-Reliable Messaging: It provides a way to reliable the message in case of failure

Web Service addressing (WS-addressing): It packages routing information as metadata within SOAP headers instead of maintaining it within the network

Web services Description Languages (WSDL): It describes what will be operations exposed by the service and its corresponding input, output, and fault elements and its corresponding data types


Different between SOAP and Rest

No comments:

Post a Comment