A look at ROA

ROA is primarily based on the concept of a resource. A resource is a distributable component that can be accessed through a standard, common interface. Each resource is associated to a unique identifier that comprises a URL.

The main concepts of ROA are centered on resources. Resources should have the following characteristics:

  • A resource should be unique and maybe linked to other related resources.
  • A resource should have a minimum of one representation.
  • A resource should have attributes and schema, it should be accessible (through its address), and it should provide a context.
  • A resource should have name; this is used to identify a resource uniquely. Resources are identified using URIs.

Although a resource link is used to represent another representation of the same resource or another resource, a resource interface is used to provide an interface to access a resource and manipulate its state information. A resource is represented using URIs. Note that data is a resource if it can be represented using a URI.

Examples of resources and URIs are as follows:

No two resources can be the same, but two or more resources can point to the same data. Here is an example:

  • http://www.packtpub.com/sales/2012/Q4
  • http://www.packtpub.com/sales/2012/Q3

The following figure shows the relationship amongst a resource, its representation, and its URI:

A look at ROA

Relation between Resource, Representation, and URI

Basic properties of ROAs

The six basic properties that an ROA implementation should hold include the following:

  • Addressability: This denotes the ability to share data and information via URIs.
  • Statelessness: This implies that every request on a RESTful web service should be self-contained. In order to achieve this statelessness nature, all calls to a RESTful service should contain relevant bits of application state in each request.
  • Connectedness: This implies that resources should contain links to related resources.
  • Representation: A resource can have multiple representations. Each of these representations should have similar URIs. In essence, a URI should contain sufficient information needed by the server to produce the desired representation. A representation is actually the description of a resource. The representation of a resource distinctly describes its state information.
    • Resource link: This is used to represent another representation of the same resource or another resource.
    • Resource interface: This is used to provide an interface to access a resource and manipulate its state information.

Basic concepts of ROAs

The four basic concepts that an ROA implementation should hold include:

  • Addressability: Addressability of a resource is its ability to expose its data through well-formed URIs.
  • Statelessness: This implies that every HTTP (moreover, because HTTP is a stateless protocol) request occurs in complete isolation.
  • Connectedness: Connectedness is the ability of a resource to be connected with another resource. In essence, it is established using links to data of the same kind.
  • A uniform interface: A RESTful service should have a uniform interface defined by HTTP's primary methods, that is, GET, PUT, POST, DELETE, and so on. Two or more representations of a particular resource are distinctly identified using URIs.

Fundamental HTTP concepts

In this section, we will discuss the basics of HTTP protocol.

The following table shows the common HTTP methods and their purpose:

Method name

Purpose

DELETE

This is used to delete a resource

GET

This is used to request for a specific representation of a resource

HEAD

This is same as GET, but it retrieves only the headers and not the body

OPTIONS

This is used to retrieve the methods supported by the resource

POST

This is used to post or submit data to be processed by the resource

PUT

This is used to create or update data using a particular representation of a resource

The following table shows the HTTP status codes and their purposes:

Status code

Description

100

Informational

200

Successful

201

Created

202

Accepted

300

Redirection

304

Not modified

400

Client error

402

Payment required

404

Not found

405

Method not allowed

500

Server error

501

Not implemented

The following table shows the HTTP redirection status codes:

Status Code

Description

300

Multiple choices

301

Moved permanently

302

Found (temporary redirection)

The following table shows the HTTP error status codes:

Status code

Description

400

Bad request

401

Unauthorized

403

Forbidden

404

Resource not found

405

Method not allowed

408

Request timeout

409

Conflict

413

Request entity too large

415

Unsupported media type

The following table shows the HTTP server error status codes:

Status Code

Description

500

Internal server error

501

Not implemented

503

Service unavailable

505

HTTP version not supported

The following table lists some resource methods and how they can be implemented using the HTTP protocol:

Method name

Description

HTTP operation

createResource

This creates a new resource

PUT

getResourceRepresentation

This is used to retrieve the representation of a particular resource

GET

deleteResource

This deletes a resource

DELETE

modifyResource

This modifies a resource

POST

getMetaInformation

This retrieves metadata of a resource

HEAD

In the section that follows, we will explore ROA. We will discuss what a resource implies, the constraints, and so on.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset