REST and OO REST


Representational State Transfer (REST) is a style of software architecture for distributed hypermedia systems such as the World Wide Web. The web is built on an architectural style called “REST”. REST provides a definition of a “resource”.

Representations are one of these things that don’t get used a lot. In most cases, a resource has only a single representation.

Look at the coffee table. What are the nouns? Cup, tray, newspaper, remote. Now, what are some things you can do to all of these things? You can get them, pick them up, knock them over, and burn them. You can apply those same exact verbs to any of the objects sitting there.

What if instead of me being able to say to you, “get the cup,” and “get the newspaper,” and “get the remote”; what if instead we needed to come up with different verbs for each of the nouns? Some verbs are more specific than others and apply only to a small set of nouns. For instance, I can’t drive a cup and I can’t drink a car. But some verbs are almost universal like GET, PUT, and DELETE. You can’t DELETE a cup but you can throw it away.

Browsers are pretty much just GET stuff. They don’t do a lot of other types of interaction with resources. It has led many people to assume that HTTP is just for “GETting”. But HTTP is actually a general purpose protocol for applying verbs to nouns.

Think about when you’re browsing around amazon.com looking for things to buy. Imagine each of the products as being nouns. Now, if they were available in a representation that a machine could understand.

At school, three or four computer systems more likely, that let administrators manage students: what classes they’re in, what grades they’re getting, emergency contacts, and information about the books you teach out of, etc. If the systems are web-based, then there’s probably a URL for each of the nouns involved here: student, teacher, class, book, room, etc. Right now, getting the URL through the browser gives you a web page. If there were a machine readable representation for each URL, then it would be trivial to latch new tools onto the system because all of that information would be consumable in a standard way. It would also make it quite a bit easier for each of the systems to talk to each other.

Java™ Application Development on Linux® – Free 599 Page eBook

Enterprise Java Virtualization:

Understanding the TCO Implications

InfoWorld’s Java IDE Comparison Strategy Guide:

Java Essential Training

Apache Jakarta Commons: Reusable Java™ Components

Enabling Rapid ROI: With Java™ – Based Business Intelligence Applications:

Each of the systems would get information from each other using a simple HTTP GET. If one system needs to add something to another system, it would use an HTTP POST. If a system wants to update something in another system, it uses an HTTP PUT.

The idea is that everything you need to use Web services is already available if you know where to look. HTTP lets you communicate your intentions through GET, POST, PUT, and DELETE requests.

Stateless Web Service Conversation Via REST

Stateless Web Service Conversation Via REST

REST is a style than a systematic way defining distributed interfaces. Given how it’s used today, there is a big gap between how it’s used and sophisticated software system development.

The key value of OO is higher level of modularity so that developers can think at the object level rather than the function and data level in the procedural programming.

One of the key concepts in REST is resource, which can be created, read, updated, and deleted (CRUD, sounds like SQL?). CRUD is also relevant at the user interface level of most applications. For example, in address book software, the basic storage unit is an individual contact entry. As a bare minimum, the software must allow the user to:

* Create or add new entries

* Read, retrieve, search, or view existing entries

* Update or edit existing entries

* Delete existing entries

Without at least these four operations, the software cannot be considered complete because these operations are so fundamental.

If we think of the different resources as objects, then the gap is filled in some way. Each resource type is defined as a class which has four methods, which correspond to CRUD.

Example:

class Employee

{

Attribute id

Attribute name

Behavior Create()

Behavior Read()

Behavior Update()

Behavior Delete()

}

Now you can easily design a URL that fits REST style:

GET http://<base_url>/obj=<obj_id>&attr=name

This gets you a XML message of attribute name.

POST http://<base_url>/obj=<obj_id>&amp; behavior=create

This activates the method create at the server side with the parameters in POST body which are not shown here.

Issues:

  • The problem is not all the object model fitting into this CRUD style.
  • Difficult to define the association of resources
  • To create OO model from an existing REST?
  • To create a REST API that is OO friendly or OO ready?

Benefits:

Single Sign-On for Java and Web Applications

Bulletproof Java Code: A Practical Strategy for Developing Functional, Reliable, and Secure Java Code

Transforming a Generic Java IDE to Your Application Specific IDE:

The Java Virtual Appliance—No OS Required

BEA WebLogic® Operations Control: Application Virtualization for Enterprise Java

Enabling Rapid ROI: With Java™ – Based Business Intelligence Applications:

References:

How I Explained REST to My Wife

Object Oriented REST

About these ads