Architectural Styles
SOAP and REST are two important Software architectures and Richardson Maturity Model helps to identify them.
Richardson maturity model
This is a measurement of how closely a system embrace different pieces of Web Technology:
-
Information resources,
-
HTTP as an application protocol,
-
Hypermedia as the medium of control.
Levels
There are 4 levels:
- Level 0
-
This is basically where SOAP is.
- There are no information resources
- HTTP is treated like a transport protocol instead of an application protocol
- There is no concept of hypermedia.
- Level 1
-
- URLs are used, but not always as appropriate information resources and everything is usually a GET request (including requests that update server state)
- There is no concept of hypermedia.
- Level 2
-
This is where most Internet-facing REST web services are because they only support non-hypermedia formats.
- URLs are used to represent information resources
- HTTP is respected as an application protocol sometimes including content negotiation
- There is no concept of hypermedia.
- Lever 3
-
- URLs are used to represent information resources.
- HTTP is respected as an application protocol including content negotiation.
- Hypermedia drivers the interactions for clients.
SOAP
Originally defined as a Simple Object Access Protocol, it is a protocol specification for exchanging structured information in the implementation of Web Services in computer networks.
SOAP is best leveraged when the lifecycle of a request cannot be maintained in the scope of a single transaction because of technological, organizational or procedural complications.
It relies on XML for its message format, and usually relies on other Application Layer protocols, most notably RPC and HTTP, for message negotiation and transmission.
SOAP can form the foundation layer of a web services protocol stack, providing a basic messaging framework upon which web services can be built. This XML based protocol consists of three parts:
- an envelope, which defines what is in the message and how to process it
- a set of encoding rules for expressing instances of application-defined datatypes
- and a convention for representing procedure calls and responses.
RESTful service
REST stand for Representational State Transfer, and it is an architectural style. It helps to create well-designed scalable distributed application resilient to change.
REST uses:
- identification of resources
- manipulation of resources through representations
- self-descriptive messages
- hypermedia as the engine of application state.
Conforming to the REST constraints is referred to as being RESTful.
REST is not limited to the HTTP protocol. RESTful architectures can be based on other Application Layer protocols if they already provide a rich and uniform vocabulary for application based on the transfer of meaningful representational state.
RESTful applications maximize the use of the pre-existing, well-defined interfaces. In HTTP REST utilizes these existing features of the HTTP protocol to allows caching and security enforcement.
MORE_ABOUT Application Layer (see http://homepages.uel.ac.uk/u0110988/page2.htm)
Rest defines how pieces of the Web Technology should be used.
In specific we have:
URL should be used to represent name of resources of information. For instance resolving the URL we can obtain
- the actual resource
- a reference to information about a particular resource
- the result of a servlet computation.
- Content negotiation
-
It is a HTTP ability by which you can ask for information in different forms (e.g.
curl -H "Accept:application/json" http://puglieseweb.com.)Note that there is a separation of the name of the name representing the resource and its form the information is returned.
- HTTP should be used as an application protocol instead of a general transport protocol
- non-hypermedia or hypermedia formats used as the medium of control.
- Information resources are manipulated by four 4 HTTP verbs (or methods)
-
This four HTTP methods act on the represented named resources and
REST defines explicitly and clearly their specific behaviours.
This allows the clients to be self-empowered to make decisions in the face of network interruptions and failure (e.g. If a client is interrupted while it is making a GET request, it should be empowered to issue it again.)
- Each request contains enough state to answer the request
- This is an important aspect of RESTful request that allows for the conditions of visibility and statelessness on the server.
REST approach clearly distinguish between:
- GET
-
Actions which make no change and thus may be cached or repeated (GET).
That implies that GET should be a (1) Saferequest==> do not modify anything on the server side. GET request transfers representations of named resources from a server to a client. The client gets back a bytestream tagged with metadata that indicates how the client should interpret it. GET are also intended to be (2) idempotent: issuing a request more than once will have no consequences.
actions which make a change but may be casually repeated without problems (PUT, DELETE)
- PUT
-
PUT is not supported by HTML forms. PUT is idempotent. It is used when the client has a URL reference to an existing resource and wishes to update it changing the state of the application.
-
PUT can be used to create a resource if the client is able to predict the resource's identity. This happen in the case the client is in control of the server side information spaces. Publishing into a user's weblog space is a typical example of PUTing to a user-specified name.
- DELETE
-
DELETE verb is typically used for information spaces we control. PUT is intended to be idempotent. We should build requests by failing silently and returning a 200 even if it has already been deleted.
- POST
-
actions which should neither be repeated nor cached.
We have a a side effect each time POST is executed.
POST is neither safe nor idempotent.
POST is used when the client cannot predict the identity of the resource it is requesting (for example if we want to create a new resource). So we POST a representation of the resource to handle (e.g. selvlet)
-
When we POST a new resource, upon successful processing, from the server we should return a 201 HTTP response code with a Location header indication the location of the newly created resource (not) the short 200 HTTP response and the body of the created resource). It can avoid a second request, but it conflates GET and SET and complicate the caching of the resource.
-
POST can be used to append (a partial update) new item in an order or a cart
-
POST can be used to submit queries either as a representation of a query or URL-encoded form values. In this case it is usually fair to return results directly from this kind of a POST since there is no identity association with the query.
This in turn enables intermediate software (be it in the form of libraries, reusable components, or entirely separate systems)to implement sensible optimisation and error-handling strategies without needing knowledge of the contentor relationships of the resources
REST is best used to manage systems by decoupling the information that is produced and consumed from the technologies that do so.
It is possible to achieve the architectural properties of:
- Statelessness
-
- Every request is totally isolated from other requests
- The server does not know about the client previous operations
- The application state is stored on the client.
This in turn enables intermediate software (be it in the form of libraries, reusable components, or entirely separate systems) to implement sensible optimisation and error-handling strategies without needing knowledge of the content or relationships of the resources.
- Addressability
-
Every interesting aspect of the application dataset is exposed by URI.
Addressability can also help in caching for better performance.
http://www.google.com/search?q=java