Pages

Showing posts with label REST. Show all posts
Showing posts with label REST. Show all posts

ETags - Roles in Web Application to Cloud Computing

A web server returns a value in the response header known as ETag (entity tag) helps the client to know if there is any change in content at a given URL which requested.When a page is loaded in the browser, it is cached.It knows the ETag of that page.The browser uses the value of ETag as the value of the header key "If-None-Match".The server reads this http header value and compares with the ETag of the page.If the value are same ie the content is not changed, a status
code 304 is returned ie. 304:Not Modified. These HTTP meta data can be very well used for predicting the page downloads thereby optimizing the bandwidth used.But a combination of a checksum (MD5) of the data as the ETag value and a correct time-stamp of modification could possible give quality result in predicting the re-download. An analysis of the effectiveness of chosing the value of ETag is described in this paper.

According to http://www.mnot.net/cache_docs/

A resource is eligible for caching if:

  • There is caching info in HTTP response headers
  • Non secure response (HTTPS wont be cached)
  • ETag or LastModified header is present
  • Fresh cache representation

Entity tags can be strong or weak validators.The strong validator provide the uniqueness of representation.If we use MD5 or SHA1, entity value changes when one bit of data is changed, while a weak value changes whenever the meaning of an entity(which can be a set of semantically related) changes.

More info on conditional requests explaining strong and weak ETags in here

In Spring MVC, Support for ETags is provided by the servlet filter ShallowEtagHeaderFilter. If you see the source here

String responseETag = generateETagHeaderValue(body);
.... ......

protected String generateETagHeaderValue(byte[] bytes) {
StringBuilder builder = new StringBuilder("\"0");
Md5HashUtils.appendHashString(bytes, builder);
builder.append('"');
return builder.toString();
}


The default implementation generates an MD5 hash for the JSP body it generated.So whenever the same page is requested, this checks for If-None-Match, a 304 is send back.


String requestETag = request.getHeader(HEADER_IF_NONE_MATCH);
if (responseETag.equals(requestETag)) {
if (logger.isTraceEnabled()) {
logger.trace("ETag [" + responseETag + "] equal to If-None-Match, sending 304");
}
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
}



This reduces the processing and bandwidth usage.Since it is a plain Servlet Filter, and thus can be used in combination any web framework.A MD5 hash assures that the actual etag is only 32 characters long, while ensuring that they are highly unlikely to collide.A deeper level of ETag implementation penetrating to the model layer for the uniqueness is also possible.It could be realted to the revisions of row data. Matching them for higher predicatability of lesser downloads of data will be an effective solution.

As per JSR 286 portlet specification Portlet should set Etag property (validationtoken) and expiration-time when rendering. New render/resource requests will only be called after expiration-time is reached.New request will be sent the Etag. Portlet should examine it and determine if cache is still good if so, set a new expiration-time and do not render.This specification is implemented in Spring MVC.(see JIRA )

A hypothetical model for REST responses using deeper Etags could be effective while an API is exposed or two applications are integrated.I have seen such an implementation using Python here

When cloud computing is considered, for Amazon S3 receives a PUT request with the Content-MD5 header, Amazon S3 computes the MD5 of the object received and returns a 400 error if it doesn't match the MD5 sent in the header.Here Amazon or Azure uses Content-MD5 which is of 7 bytes.

According to the article here in S3 for some reason the entity was updated with the exact same bits that it previously had, the ETag will not have changed, but then, that's probably ok anyway.

According to S3 REST API,

Amazon S3 returns the first ten megabytes of the file, the Etag of the file, and the total size of the file (20232760 bytes) in the Content-Length field.

To ensure the file did not change since the previous portion was downloaded, specify the if-match request header. Although the if-match request header is not required, it is recommended for content that is likely to change.


The ETag directive in the HTTP specification makes available to developers to implement caching, which could be very effective at the transport level for REST services as well as web applications.The trade-off would be, there may be security implications to having data reside on the transport level.

But in the case of static files which is having a large "Expires" value and clustered files, Etag will not be effective because of the unique checksum for files that are distributed will be transported to client for each GET requests.By removing the ETag header, you disable caches and browsers from being able to validate files, so they are forced to rely on your Cache-Control and Expires header.Thus by reducing the header size which was having the checksum value.

Few videos i liked from Mix 09

I have worked on some .NET RIA projects before.I saw some videos from Mix09, and sharing some I liked.

Building a Rich Social Network Application


Learn how to build a social networking site using Microsoft Silverlight.Also explains how to mash up existing services, how to tag and store data in back-end services,and how to build a rich and engaging experience.






Get Microsoft Silverlight











Get Microsoft Silverlight


Visit this website for different ux patterns



http://quince.infragistics.com




There are different patterns for designing an application .See this video for how to enable rich communication patterns between your AJAX Web pages and Web server using existing and new features in WCF, Windows Communication Foundation.






Get Microsoft Silverlight





I have written about RESTful services before.In this video, look for ADO.NET Data Services matching REST.






Get Microsoft Silverlight


For Three Tier RIA Pattern

RESTful Java , some links

I would like to share some interesting links  for developing Restful applications in java 

JSR 311: JAX-RS: The JavaTM API for RESTful Web Services:
This JSR will develop an API for providing support for RESTful(Representational State Transfer) Web Services in the Java Platform.

Jersey - JSR 311:JAXRS implementation

REST for Java developers, Part 1: It's about the information, stupid - JavaWorld

REST for Java developers: Restlet for the weary - JavaWorld

REST for Java developers, Part 3: NetKernel - JavaWorld

JavaFX RESTful Pet Catalog Client

Some pdfs


If you are a Netbeans fan you should view these screencasts 
RESTful Web Services Pet Catalog
RESTful Web Services in NetBeans IDE 6.0
Building an End-to-End Restful Web Application
RESTful Web Services Pet Catalog - NetBeans IDE 6.5
YouTube: NetBeans REST Web Services, Building and Deploying (Part 1)
YouTube: NetBeans REST Testing and Invoking REST Resources (Part 2)


About HATEOAS

I think designing a REST URL is really challenging The resources are represented as hyperlinks.When REST applications are to be designed do business logic states depend on REST URL design ? The changes in application state are done through hyperlinks.So every possible state of applications are exposed as services and state changes are also exposed as urls.So we can draw a graph depicting change in states.So the transitions are done at run time while using the application.It is decided by the server.So the hypermedia as the engine of application state (HATEOAS) becomes a design constraint.So if the server responds as a set of links depicting the transitions, the consumer client can traverse through them to arrive at the final state... Concept seems pretty straightforward, but are there any underlying implementation complexities ? The relationship between resources can be logical, but the server makes relationships for the application.The client can have states defined by hypermedia elements.The tags like IMG,OBJECT,SCRIPT embeds resource within itself.The CSS can have image background links.So these urls can locate to the resource globally.The name space is defined by web itself.I think the scene becomes more interesting when web service discoveries,ordering of interactions, business logic making the client dynamic by the features of this concept.The libraries and frameworks as we know provide a way to call a single function and the system itself calls other functions internally.So this form of calling a single URL as a an entry point for calling other related urls linking logic or resource states performs same functionality like an interactive website.The urls can change at any time.The urls become a constraint in designing for a dynamic application.There will be a tight coupling for the resources and the client due to these permanent urls which will have to be residing forever.So the solution ? The response can be documents of urls for the client to traverse as i mentioned above as to call the resource from a single entry point... which is what HATEOAS is about

With a truly REST based architecture you are free to change just about anything about the disposition and naming of resources in the system, except for a few well known start point URIs. You can change the URI shapes (for example, if you decide that you really hate the currently scheme). You can relocate resources to different servers (for example, if you need to partition you data). Best of all, you can do those things without asking any ones permission, because clients will not even notice the difference.

http://barelyenough.org/blog/2007/05/hypermedia-as-the-engine-of-application-state/

What is Computational REST ?

I have written about REST before.CREST is about computational REST.I think the concept will be a milestone in developing applications on Resource Oriented Architecture (ROA).ROA is a set of guidelines of implementing REST architecture.This wikipedia article give a simple idea of the world of representations.

The image is taken from here gives an illustration of the kind of message passing used in Representational State Transfer.

REST is architectural style of distributed systems.RESTful Webservices are gaining importance in developing scalable applications.The web 2.0 technologies,ajax,mashups,comet,pub-sub technologies do envision the power of computing using internet.The computational resources in the web can be accessed by URIs.Whats buzz CREST ?

A client needs to execute a program.The origin server executes the code and return the result.This form the basis of CREST or Computational REST. Code snippets having conditional logic can be sent and the response will reflect the behavior of application.So the application can become more client centric.It can be like a service behavior changes with different client conditions.Computational REST (CREST) as an architectural style to guide the construction of computational web elements... The idea is similar to mobile code.This idea is originated from Rethinking Web Services from First Principles .They have given the underlined principles of REST and CREST.The technology is under research.So internet technologies are heating up.
The technology for using REST for process intensive integration is in a budding stage only.The distributed processing in REST way.. Programmability of web is becoming complex and disruptive!

RESTlet and REST in GWT



REST has been widely accepted as an architectural concept for web applications.Web 2.0 technology has became the backbone of future pervasive and distributed computing.When I went through some search on REST based application development for Java I came to know about Restlet framewok.Recently Restlet was ported to Google web toolkit.GWT is successful like the time when applet came to web world.This frontend technology from Google brings Java to web browsers.It uses GWT-RPC mechanism to invoke server methods.The port, named “Restlet-GWT module” that helps to leverage existing RESTful back-ends.Days back the team released its new milestone Restlet 1.1 M5
They have updated their wiki for the how-to documentation of developing applications based on the new enhancement.
There is another implementation to develop RESTful applications using GWT-REST
They can be used as a replacement or used along-side with GWT-RPC , I think that will make it very useful.




Jérôme Louvel, Restlet founder based in Levallois-Perret, France, has established the Restlet project to create a REST framework on top of the Java Servlet API to "bring the simplicity and efficiency of the REST architectural style to Java developers."He is the founder of Noelios Consulting

The REST - part1

Representational State Transfer is the basic architecture of Web.
"Representation State Transfer is intended to evoke an image of how a well-designed Web application behaves: a network of web pages (a virtual state-machine), where the user progresses through an application by selecting links (state transitions), resulting in the next page (representing the next state of the application) being transferred to the user and rendered for their use.",
as quoted by Roy Fielding who coined REST in his Ph.D dissertation to describe an architecture style of networked systems.
The resources scattered all around the web are identified by its URI.These URIs are the equivalent of a noun.Think how many nouns !! From "flick"ring pixels to "twitter"ing fingers.All the thoughts congregate to the web.Verbs describe the actions.We use verbs for funcion names in programming.GET is the action to fetch a web page , the representation of the resource identified by URI.It is the undamental action of a browser.Other verbs are : POST to add information, PUT to update information, DELETE removes information.They make the CRUD verbs for web as a database.REST is like modelling the web services as URI addressable resources. These REST type URIs are logical ones than physical.The URLs are parsed and the required data ie the represenatio is sent back to client. So the state of client changes as per the recievables.If we look in a hypertext document we see hyperlinks to other resources.
Each resource representation contains hyper-links. Following a hyper-link takes the client to the next state. Thus, within the resource representations themselves are pointers to the next states.
If we consider this concept in regard to OOP , it is like a "HTTP Object Model", as it was originally referred.
The REST-RPC style in flickr API looks like :-
GET services/rest?api_key=xx&method=flickr.photos.search&tags=sunflower
It gets the images with tag sunflower using the search method.
The Web uses embedded identifiers rather than link servers.So the authors need an identifier that closely matches the semantics they intend by a hypermedia reference, allowing the reference to remain static even though the result of accessing that reference may change over time. REST accomplishes this by defining a resource to be the semantics of what the author intends to identify, rather than the value correspondingto those semantics at the time the reference is created. It thus integrates with "tagging" on web .So the REST becomes the fundamental principle for a semantic web.