Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

a RESTful webserver should think in resources, these are the basic elements of information accessible

a resource can also have different representations (html, pdf, atom, ...)

and the URL is an important identifier, giving bookmarkability of resources/representations, and modeling many things in a standardized way: hierarchy of resources, request parameters, etc.

now sling:
the URL / resource hierarchy is implemented by using JCR, a tree structured store

sling only maps from the URL to JCR (aka it finds the resource first) and then finds out which representation is needed (also part of the URL or maybe the HTTP headers) (to be exact, representation is for GET requests, for PUT/POST we need a "handler" or resourceType)

the handlers are valid for a specific resource type, ie. resources in jcr have the attribute "sling:resourceType", which points back to the handlers, ie. the scripts that can handle the resource in question

each handler is typically a directory in JCR itself with scripts for the various representations and the PUT, POST methods

those representations or handlers are implemented by scripts (quick and cool) or plain old Java servlets (IDE support + managed code)

(scripts can be in many popular languages (javascript, ruby, python, etc.) - sling as it is written in Java uses the Java Scripting framework (JSR-223))


to repeat: what happens when a HTTP request comes in:
1) sling finds the resource in the JCR (or some other place)
2) depending on HTTP method

for a GET:
GET.1) sling determines the representation wanted and finds the handler (script/servlet)
GET.2) this is done by looking at sling:resourceType (an attachement to the JCR node) and calling "resourceType/<extension>.js" (.js could be .py, .rb, whatever scripting language is available)
GET.2) handler runs with full access to its resource (JCR node)

for a PUT:
PUT.1) sling looks for a PUT.js in the resourceType script folder
PUT.2) or sling does the upload automatically

for a POST:
POST.1) sling looks for a POST.js in the resourceType script folder
POST.2) or sling creates JCR nodes/properties based on a simple request parameter mapping

3) response is sent back, done!