Saturday, May 28, 2022

What is a WEB SERVICE?



            Interoperable: can be used by any application built in any technology.


=================================================================

How does data exchange between applications take place?



How can we make the web services platform independent?

Ans. Request and Response should be in proper formats, to support web service on different platforms
  • XML
  • JSON


How does Application A knows the format of Request and Response?


=================================================================

Web Service - Key Terminologies

Request: i/p to web service

Response: o/p from web service

Message Exchange Format: format of request and response

Service Provider or Server: which hosts the web service. 

eg. Web Service is a service provider

Service Consumer or Client: who consumes the web service

eg. Application A, JavaApplication, DotNetApplication, PHPApplication is a service consumer. 



Contract b/w service provider and service consumer.


Transport: how service is called.
  • One, weather service is exposed on the internet i.e. HTTP
    • HTTP is over the web like we use the URL in browser similarly Application_A will call web service.
  • Two, weather service is exposed over the transport which is queue i.e. MQ. 
    • The service requester would place a message in the queue. 
    • The service provider would be listening on the queue. 
    • As soon as there's request on the queue it would take the request, do the processing of it, create the response and put it back in the queue. 
    • The service requester would get the response from the queue.
    • The transport will be MQ, here it is WebSphere MQ


 =================================================================

Types of Web Services

  1. SOAP
  2. REST
SOAP and REST are not really comparable. 

REST defines an architectural approach.
SOAP poses restrictions on the format of XML which is exchanged between your service provider and service consumer.

Introduction of SOAP Web Services

  • SOAP defines a specific way of building web services.
  • Here we use XML as a request exchange format. 
  • It defines the specific XML request and response structure. 
SOAP
  • Format
    • XML Request and Response
  • Transport
    • SOAP over MQ
    • SOAP over HTTP
  • Service Defination
    • WSDL

  • WSDL defines the end point i.e. where your service is exposed.
  • It defines all the operations exposed
    • get all codes details
    • add a new course
    • delete course
  • Also, specifies the request and response structure.


SOAP is all about adhering to services XML structure. Adhering to envelop header and body.
 Once we have your request and response in that structure, then we can say that we are developing SOAP web services. 


=================================================================

Introduction to RESTful Web Service

when we enter the URL in the browser, a request is sent to the website server.
The website server responds back with a response. 

What is the format of request and response? 
These requests and responses are in a format defined by HTTP protocol.
In addition to request header and request body, HTTP also defines HTTP Methods and HTTL Status Codes.

Roy Fielding (who invented HTTP) said, why don't we use HTTP to develop web services.  
Hence, concept of RESTful webservices came.


RESTful web services try to define services using different concepts that are already present in HTTP.
Most important abstraction in REST is something called resource.
A resource is ant thing that you want to expose to outside world through your application.

eg. in TODO Management Service 
  • users are resource who are using it, Let Ram is a resource. 
  • specific TODO is a resource
  • LIST of TODOs is also a resource.

So, we define a URI for these resources.

  • A resource has an URI (Uniform Resource Identifier)
    • /user/ram/todos/1
    • /user/ram/todos
    • /user/ram
  • Resources ca have different representations
    • XML
    • HTML
    • JSON

The most important thing is the fact that you can define your resource and perform actions on these resources using whatever facilities are provided by HTTP.

 EXAMPLE
  • Create a User: POST /users
  • Delete a User: DELETE /users/1
  • Get all User: GET /users
  • Get one Users: GET /users/1

REST

  • Data Exchange Format
    • No restriction. JSON is popular
  • Transport
    • Only HTTP
  • Service Defination
    • No Standard. WADL/Swagger


Nginx Setup

 

1. yum install yum-utils 

2. yum-config-manager --add  https://openresty.org/package/centos/openresty.repo 

3. yum install openresty /usr/local/openresty/nginx 

4. cd  /usr/local/openresty/nginx/conf 

5. Add the proxy settings as per needs 

5. Edit nginx.conf to update the ip of the server in "proxy redirect" sections .For example, current server ip is 18.32.76.34.

6. Remove nginx.conf.default  

7. cd /usr/local/openresty/nginx/sbin  

8. nginx -p /usr/local/openresty/nginx/ -c conf/nginx.conf 

9. pkill -9 docker  



#user  nobody;

worker_processes  8;

worker_rlimit_nofile 100000;

#error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

 

#pid        logs/nginx.pid;

pid    /var/run/nginx.pid;

 

 

events {

    worker_connections 100000;

    use epoll;

    multi_accept on;

 

}

 

 

http {

    include       mime.types;

    default_type  application/octet-stream;

     ################# Gzip Settings ################

    gzip on;

    gzip_comp_level 4;

    gzip_min_length 1024;

    gzip_proxied any;

    gzip_static on;

    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js application/soap+xml;

    gzip_disable "MSIE [1-6]\.";

map $http_x_forwarded_proto $http_scheme

{ ~https https; default http; }

 

 

 

        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

                  '$status $body_bytes_sent '

                  'X-Auth-Token: "$sent_http_x_auth_token"';

 

 

 

 

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

    #                  '$status $body_bytes_sent "$http_referer" '

    #                  '"$http_user_agent" "$http_x_forwarded_for"';

 

    #access_log  logs/access.log  main;

 

    sendfile        on;

    tcp_nopush     on;

    tcp_nodelay        on;

    keepalive_timeout  30;

    keepalive_requests 10000;

    reset_timedout_connection on;

    client_body_timeout 30;

    send_timeout 300;

    #gzip  on;

 

    server {

        listen       80;

        server_name  localhost;

        access_log  /usr/local/openresty/nginx/logs/frontend.log ;

        error_log   /usr/local/openresty/nginx/logs/error.log;

 

        #charset koi8-r;

 

        #access_log  logs/host.access.log  main;

 

        location / {

            root   html;

            index  index.html index.htm;

        }

 

        #error_page  404              /404.html;

 

        # redirect server error pages to the static page /50x.html

        #

         error_page   500 502 503 504  /50x.html;

        underscores_in_headers on;

 

        location = /50x.html {

            root   html;

 

        }

 

############################Redirection Logic For Comp1######

 

location /comp1/ {

 # proxy_redirect  http://12.89.29.40/comp1/api/v2.0/search/;

 #   proxy_read_timeout 60s;

      real_ip_header      X-Forwarded-For;

        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

          proxy_set_header X-Forwarded-Proto $http_scheme;

           proxy_set_header  X-Real-IP $remote_addr;

                add_header  Access-Control-Allow-Origin *;

 proxy_pass      http://12.89.29.40:9023$request_uri;

 #                      ################# Gzip Settings ################

           gzip  on;

           gzip_comp_level 4;

           gzip_min_length 10240;

           gzip_proxied expired no-cache no-store private auth;

           gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js application/soap+xml;

           gzip_disable "MSIE [1-6]\.";

 

             }  

   

}


Popular Posts

Most Featured Post

GitHub: Squash all commits in PR

  Command Meaning git fetch origin Get the latest origin/master . git reset --soft origin/master Move your branch to match origin/master , b...