Skip to content

Microservices with Spring Boot and Spring Cloud

Amitha R edited this page Dec 17, 2020 · 12 revisions

Microservices with Spring Boot and Spring Cloud

Introduction to Web Services

What is a Web Service?

  • Service delivered over the web.
  • Software system designed to support interoperable machine-to-machine interaction over a network.
Web Services - 3 Keys:
  1. Designed for machine-to-machine(or application-to-application) interaction.
  2. Should be interoperable - Not platform dependent. (Application A (Java), Application B(.Net), Application C (PHP)) - Irrespective of their technologies they should be able to talk to the ToDo service.
  3. Should allow communication over a network. (Communication should not be bound within a local machine).

Important questions related to web services

  1. How does data exchange between applications take place?

              -----Request------->
    

| Application A |---------------------| WebService |

             <-----Response-------
  • Application A is consuming a web service.
  1. How can we make web services platform independent?
  • The Request and Response of the webservice must be platform independent.
  • There are two popular formats for requests and responses.

a. XML

  • Extensible Markup Language.

<getCourseDetailsRequest>
<id>Course1</id>
</getCourseDetailsRequest>

b. JSON

  • Javascript Object Notation [ { "id": 1, "name": "Even", }, { "id": 2, "name": "Odd", } ]
  1. How does the Application A know the format of Request and Response?
  • Application A needs to send a request to the web service and once it gets the response it needs to be able to process it.
  • Service Definition:
  • Every web service offers a service definition
  • The service definition would specify:
    i. Request/Response Format - JSON, XML, etc.
    ii. Request Structure
    iii. Response Structure
    iv. Endpoint

Web Services - Key Terminology

  1. Request and Response
  • Request - Input to the web service.
  • Response - Output from a web service.
  1. Message Exchange Format
  • It is the format of the request and the response.
  • XML and JSON
  1. Service Provider or Server & Service Consumer or Client

              -----Request------->
    

| Application A |---------------------| WebService |

             <-----Response-------
  • Application A wants to consume a service from the web service.
  • The Web Service is called the service provider.
  • Service provider is the one which hosts the web service.
  • The service consumer is the one which is consuming the web service. Application A is the client.

| Java Application | ----------------------> | WebService |
| DotNet Application |-----------|
| PHP Application |-----------|

  • In the above example, the java application, the dot net application and the PHP application are all consumers of the web service.
  1. Service Definition
  • The Service Definition is the contract between the service provider and the service consumers.
  • The Service Definition states:
    1. Request/Response Format
    2. Request Structure
    3. Response Structure
    4. Endpoint
  1. Transport (HTTP and MQ)
  • Transport defines how a service is called - over the web or queue.
  • In MQ - use communication over a queue.
    • A service requestor would place a message in a queue.
    • The service provider would be listening on the queue.
    • As soon as there's a request on the queue it would take the request, do the processing of it, create the response from the queue and place it back in the queue.
    • The transport used is the MQ.

Communication Over Queue


Introduction to SOAP Web Service

  • SOAP - Simple Object Access Protocol.
  • SOAP defines a specific way of building web services.
  • SOAP uses XML for Request and Response exchange format.
  • SOAP defines a specific XML request and response structure.
    • It should have a SOAP-ENVELOPE
      • SOAP-ENV: Header
        • Contains meta information like authentication, authorization, signature, etc.
      • SOAP-ENV: Body
        • Real content of the request or response.
  • SOAP defines a format for your request and response.
  • SOAP does not pose any restrictions on your transport - can either use HTTP or MQ.
  • In SOAP, the service definition is typically done using web service definition language (WSDL).
  • WSDL Defines:
    1. End point
    2. All operations (CRUD)
    3. Request Structure
    4. Response Structure

SOAP Web Service


Introduction to RESTful Web Services

  • REST - REpresentational State Transfer - coined by Roy Fielding.
  • Roy Fielding - developed HTTP protocol.
  • RESTful web services try to define services using the different concepts that are already present in HTTP.

Resource - Key Abstraction

  • A resource is anything that you would want to expose to the outside world through your application.
  • A resource has an URI (Uniform Resource Identifier):
  • /user/A/todos/1
  • /user/A/todos
  • /user/A
  • A Resource can have different representations
  • XML
  • HTML
  • JSON
  • EXAMPLES
  • Create a User - POST /users
  • Delete a User - DELETE /users/1
  • Get all Users - GET/users
  • Get one Users - GET /users/1
  • Data Exchange Format:
  • No Restriction. JSON is popular.
  • Transport
  • Only HTTP
  • Service Defintion
  • No Standard. WADL/ Swagger/...
  • WADL - Web Application Definition Language - Format to specify your RESTful Web services.
REST focuses on your resources and how do you perform actions on them making best use of HTTP.

Clone this wiki locally