Tuesday, June 6, 2017

Web Services Introduction

Web Service definition

  • A web service is a distributed software whose components can be deployed and executed on distinct devices.
  • A web service consists of a service (a.k.a. producer) and a client (a.k.a. consumer or requester).

Web service terminology

  • message: the basic unit of communication between a web service and a requester; data to be communicated to or from a web service as a single logical transmission.
  • operation: a description of an action supported by the service; a set of messages related to a single web service action.
  • synchronous: an interaction is said to be synchronous when the participating agents must be available to receive and process the associated messages from the time the interaction is initiated until all messages are actually received or some failure condition is determined.
  • asynchronous: an interaction is said to be asynchronous when the associated messages are chronologically and procedurally decoupled.

Web Service over HTTP

  • A web service is an application typically running over HTTP.
  • A web service over HTTP is a web service that uses the HTTP as transport, HTTP messages are infrastructure.

Web Service architecture

  • The architecture of a simple web service is a client and a server.
  • The architecture of a complicated web service have many clients and a service composed of other services.
    • for example, an e-commerce service can be composed of multiple software components (each hosted on a separate web server) and any combination of PCs, tablets, mobile phones and other networked devices may host programs that make requests to the service.

Web services come in two flavors: SAOP-based and REST-style.

  • SOAP is an XML dialect that specifies the structure of XML documents that count as SOAP envelopes
  • A REST-style service is one that treats HTTP not only as a transport infrastructure but also as a set of guidelines for making service requests and responses.

Web service features

  • Web service major attractiveness is interoperability: clients and services can interact despite differences in programming languages, operating systems and hardware platforms.
  • XML and JSON are web service data interchange formats that provide an intermediary level and handle the differences in data types between different programming languages.

REST

REST definition

  • REST (REpresentational State Transfer) is an acronym created by Roy Fielding to describe the principles for building software systems that are known as REST-style or RESTful web service..
  • REST is an software architecture style for hypermedia systems.
    • Hypermedia systems are systems where text, pictures, audio, video and other media are stored in network hosts and connected through hyperlinks.
    • the web is the example of hypermedia system

RESTful Systems and HTTP

  • HTTP is both a transport protocol and a messaging system
  • HTTP requests and HTTP responses are the messages
  • HTTP payloads can be typed using the MIME type system
  • HTTP response status codes notify the requester about whether the request was successful or not.

REST centers around the concept of web resource.

  • A resource is something accessible in the web through HTTP because the resource has an URI.
    • the URI (Uniform Resource Identifier) has two subtypes: the URL (Locator) and the URN (Name)
    • A URL is an URI that references a web resource: it specifies the location on a computer network and a mechanism for getting the representation of it. For example, a web browsers may display the URL http://www.domain.com/index.html
    • A URN is a URI that identifies a resource by name in a particular namespace. For example, a book has an ISBN (a string composed of 10 digits) that acts as an URN.
  • In practice, a resource is a piece of information accessible on the web which may have hyperlinks to it. Hyperlinks use URIs.
    • For example, the Pink Floyd rock band is a resource.
  • Resources may have one or more representations. Those representations in the web are MIME typed.
    • For example, the page on wikipedia about Pink Floyd has text/html MIME type.
  • Resources have a state which may change over time and resource’s representations capture this state.
    • For example, Pink Floyd recorded many albums during their career. The Pink Floyd’s discography make up Pink Floyd resource’s representation.
  • Resources can be persisted on a data store.

RESTful requests target a resource

  • when a web service access a resource, the requester receives a representation of the resource. If the retrieve request succeeds, a typed representation of resource (ex. text/html) is transferred from the machine hosting the service.
  • When a RESTful client accesses a resource it does two things: names the resource by giving its URI and specifies the verb (HTTP method) that indicates the operation the client wishes to do (create a new resource, retrieve a resource, update an existing resource and delete an existing resource)
  • In practice, a RESTful request contains the name of the resource and the client operation on the resource
    RESTful request ≡ resource’s URI + client operation

In the REST, HTTP works as an API

  • HTTP has its methods: each method corresponds to a CRUD operation.
    HTTP methodCRUD operation
    POST Create
    GET Retrieve
    UPDATE Update
    DELETE Delete
  • HTTP has its response code. For example 200 Response Success, 404 Not Found and 500 Internal Server Error
  • To sum up, HTTP gives methods and MIME types to client requests, HTTP provides service responses with status codes and MIME types.

References

Web Resource on Wikipedia
Web Services Description Language (WSDL) on W3C
Web Service Glossary on W3C
Representational State Transfer on Wikipedia

No comments :

Post a Comment