You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Bruce Edge <br...@nextissuemedia.com> on 2014/11/12 19:49:03 UTC

HATEOAS compliant json self/child references from sling?

Can one retrieve HATEOAS format responses form sling?

%> curl -qu admin:admin http://localhost:8090/var/content.tidy.json
{
  "jcr:createdBy": "admin",
  "jcr:mimeType": "application/octet-stream",
  "jcr:created": "Sat Nov 08 2014 16:17:51 GMT-0800",
  "jcr:lastModified": "Sat Nov 08 2014 16:17:51 GMT-0800",
  "jcr:primaryType": "sling:Folder"
}

Using a HATEOAS server I would expect something like this:
{
  "jcr:createdBy": "admin",
  "jcr:mimeType": "application/octet-stream",
  "jcr:created": "Sat Nov 08 2014 16:17:51 GMT-0800",
  "jcr:lastModified": "Sat Nov 08 2014 16:17:51 GMT-0800",
  "jcr:primaryType": ³sling:Folder"
 "_links":{
    "self":{
      "href":"http://localhost:8090/var/content"
    }
  }  
}

Is it possible to have sling insert both self and child references into
all json responses?

-Bruce


Re: HATEOAS compliant json self/child references from sling?

Posted by Sarwar Bhuiyan <sa...@gmail.com>.
https://github.com/davidjgonzalez/com.activecq.samples/blob/master/core/src/main/java/com/activecq/samples/resourcedecorators/impl/SampleResourceTypeResourceDecorator.java


On Wednesday, November 12, 2014, Bruce Edge <br...@nextissuemedia.com>
wrote:

> That sounds pretty close to ideal.
>
> <noob warning>
> Is there any sample/contrib code I could use as a starting point to create
> an osgi bundle that adds a ResourceDecorator?
>
>
> -Bruce
>
> From: Sarwar Bhuiyan <sarwar.bhuiyan@gmail.com <javascript:;><mailto:
> sarwar.bhuiyan@gmail.com <javascript:;>>>
> Reply-To: "users@sling.apache.org <javascript:;><mailto:
> users@sling.apache.org <javascript:;>>" <users@sling.apache.org
> <javascript:;><mailto:users@sling.apache.org <javascript:;>>>
> Date: Wednesday, November 12, 2014 at 10:57 AM
> To: "users@sling.apache.org <javascript:;><mailto:users@sling.apache.org
> <javascript:;>>" <users@sling.apache.org <javascript:;><mailto:
> users@sling.apache.org <javascript:;>>>
> Subject: Re: HATEOAS compliant json self/child references from sling?
>
> Maybe using a ResourceDecorator which inspects each resource and injects
> the HAL or whatever properties into the resource before rendering. The
> default get servlet may or may not render it accordingly but if you've got
> your own selector you can pretty much enhance your output however you like
> since href can just be generated from resource.getPath()
>
> That might not be what you're looking for but it will require a little bit
> of code
>
> On Wednesday, November 12, 2014, Bruce Edge <bruce.edge@nextissuemedia.com
> <javascript:;><mailto:bruce.edge@nextissuemedia.com <javascript:;>>>
> wrote:
>
> Can one retrieve HATEOAS format responses form sling?
>
> %> curl -qu admin:admin http://localhost:8090/var/content.tidy.json
> {
>    "jcr:createdBy": "admin",
>    "jcr:mimeType": "application/octet-stream",
>    "jcr:created": "Sat Nov 08 2014 16:17:51 GMT-0800",
>    "jcr:lastModified": "Sat Nov 08 2014 16:17:51 GMT-0800",
>    "jcr:primaryType": "sling:Folder"
> }
>
> Using a HATEOAS server I would expect something like this:
> {
>    "jcr:createdBy": "admin",
>    "jcr:mimeType": "application/octet-stream",
>    "jcr:created": "Sat Nov 08 2014 16:17:51 GMT-0800",
>    "jcr:lastModified": "Sat Nov 08 2014 16:17:51 GMT-0800",
>    "jcr:primaryType": ³sling:Folder"
>   "_links":{
>      "self":{
>        "href":"http://localhost:8090/var/content"
>      }
>    }
> }
>
> Is it possible to have sling insert both self and child references into
> all json responses?
>
> -Bruce
>
>
>
>

Re: HATEOAS compliant json self/child references from sling?

Posted by Bruce Edge <br...@nextissuemedia.com>.
That sounds pretty close to ideal.

<noob warning>
Is there any sample/contrib code I could use as a starting point to create an osgi bundle that adds a ResourceDecorator?


-Bruce

From: Sarwar Bhuiyan <sa...@gmail.com>>
Reply-To: "users@sling.apache.org<ma...@sling.apache.org>" <us...@sling.apache.org>>
Date: Wednesday, November 12, 2014 at 10:57 AM
To: "users@sling.apache.org<ma...@sling.apache.org>" <us...@sling.apache.org>>
Subject: Re: HATEOAS compliant json self/child references from sling?

Maybe using a ResourceDecorator which inspects each resource and injects
the HAL or whatever properties into the resource before rendering. The
default get servlet may or may not render it accordingly but if you've got
your own selector you can pretty much enhance your output however you like
since href can just be generated from resource.getPath()

That might not be what you're looking for but it will require a little bit
of code

On Wednesday, November 12, 2014, Bruce Edge <br...@nextissuemedia.com>>
wrote:

Can one retrieve HATEOAS format responses form sling?

%> curl -qu admin:admin http://localhost:8090/var/content.tidy.json
{
   "jcr:createdBy": "admin",
   "jcr:mimeType": "application/octet-stream",
   "jcr:created": "Sat Nov 08 2014 16:17:51 GMT-0800",
   "jcr:lastModified": "Sat Nov 08 2014 16:17:51 GMT-0800",
   "jcr:primaryType": "sling:Folder"
}

Using a HATEOAS server I would expect something like this:
{
   "jcr:createdBy": "admin",
   "jcr:mimeType": "application/octet-stream",
   "jcr:created": "Sat Nov 08 2014 16:17:51 GMT-0800",
   "jcr:lastModified": "Sat Nov 08 2014 16:17:51 GMT-0800",
   "jcr:primaryType": ³sling:Folder"
  "_links":{
     "self":{
       "href":"http://localhost:8090/var/content"
     }
   }
}

Is it possible to have sling insert both self and child references into
all json responses?

-Bruce




Re: HATEOAS compliant json self/child references from sling?

Posted by Sarwar Bhuiyan <sa...@gmail.com>.
Maybe using a ResourceDecorator which inspects each resource and injects
the HAL or whatever properties into the resource before rendering. The
default get servlet may or may not render it accordingly but if you've got
your own selector you can pretty much enhance your output however you like
since href can just be generated from resource.getPath()

That might not be what you're looking for but it will require a little bit
of code

On Wednesday, November 12, 2014, Bruce Edge <br...@nextissuemedia.com>
wrote:

> Can one retrieve HATEOAS format responses form sling?
>
> %> curl -qu admin:admin http://localhost:8090/var/content.tidy.json
> {
>   "jcr:createdBy": "admin",
>   "jcr:mimeType": "application/octet-stream",
>   "jcr:created": "Sat Nov 08 2014 16:17:51 GMT-0800",
>   "jcr:lastModified": "Sat Nov 08 2014 16:17:51 GMT-0800",
>   "jcr:primaryType": "sling:Folder"
> }
>
> Using a HATEOAS server I would expect something like this:
> {
>   "jcr:createdBy": "admin",
>   "jcr:mimeType": "application/octet-stream",
>   "jcr:created": "Sat Nov 08 2014 16:17:51 GMT-0800",
>   "jcr:lastModified": "Sat Nov 08 2014 16:17:51 GMT-0800",
>   "jcr:primaryType": ³sling:Folder"
>  "_links":{
>     "self":{
>       "href":"http://localhost:8090/var/content"
>     }
>   }
> }
>
> Is it possible to have sling insert both self and child references into
> all json responses?
>
> -Bruce
>
>

JSON-LD Re: HATEOAS compliant json self/child references from sling?

Posted by Andreas Kuckartz <a....@ping.de>.
Please use the W3C standard JSON-LD for such purposes:
http://www.w3.org/TR/json-ld/

See also:
http://json-ld.org/

Cheers,
Andreas


Bruce Edge wrote:
> Can one retrieve HATEOAS format responses form sling?
> 
> %> curl -qu admin:admin http://localhost:8090/var/content.tidy.json
> {
>   "jcr:createdBy": "admin",
>   "jcr:mimeType": "application/octet-stream",
>   "jcr:created": "Sat Nov 08 2014 16:17:51 GMT-0800",
>   "jcr:lastModified": "Sat Nov 08 2014 16:17:51 GMT-0800",
>   "jcr:primaryType": "sling:Folder"
> }
> 
> Using a HATEOAS server I would expect something like this:
> {
>   "jcr:createdBy": "admin",
>   "jcr:mimeType": "application/octet-stream",
>   "jcr:created": "Sat Nov 08 2014 16:17:51 GMT-0800",
>   "jcr:lastModified": "Sat Nov 08 2014 16:17:51 GMT-0800",
>   "jcr:primaryType": ³sling:Folder"
>  "_links":{
>     "self":{
>       "href":"http://localhost:8090/var/content"
>     }
>   }  
> }
> 
> Is it possible to have sling insert both self and child references into
> all json responses?
> 
> -Bruce

Re: HATEOAS compliant json self/child references from sling?

Posted by Robert Munteanu <ro...@apache.org>.
On Wed, Nov 12, 2014 at 9:05 PM, Jason Bailey <Ja...@sas.com> wrote:
> Not unless you add it yourself. As a note, you may not want to design your application where you are relying on the default json renderer to supply information to the front end client. It can reveal more information and structure then a lot of people are comfortable with.

That's a fair point. However, I would also argue that you should take
great care to design your application such as the content structure
and the ACLs applied to it will naturally separate the information
that you don't want visible from the one you can expose to everyone.

Cheers,

Robert

>
> -----Original Message-----
> From: Bruce Edge [mailto:bruce.edge@nextissuemedia.com]
> Sent: Wednesday, November 12, 2014 1:49 PM
> To: users
> Subject: HATEOAS compliant json self/child references from sling?
>
> Can one retrieve HATEOAS format responses form sling?
>
> %> curl -qu admin:admin http://localhost:8090/var/content.tidy.json
> {
>   "jcr:createdBy": "admin",
>   "jcr:mimeType": "application/octet-stream",
>   "jcr:created": "Sat Nov 08 2014 16:17:51 GMT-0800",
>   "jcr:lastModified": "Sat Nov 08 2014 16:17:51 GMT-0800",
>   "jcr:primaryType": "sling:Folder"
> }
>
> Using a HATEOAS server I would expect something like this:
> {
>   "jcr:createdBy": "admin",
>   "jcr:mimeType": "application/octet-stream",
>   "jcr:created": "Sat Nov 08 2014 16:17:51 GMT-0800",
>   "jcr:lastModified": "Sat Nov 08 2014 16:17:51 GMT-0800",
>   "jcr:primaryType": ³sling:Folder"
>  "_links":{
>     "self":{
>       "href":"http://localhost:8090/var/content"
>     }
>   }
> }
>
> Is it possible to have sling insert both self and child references into all json responses?
>
> -Bruce
>

Re: HATEOAS compliant json self/child references from sling?

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi,

On Thu, Nov 13, 2014 at 1:32 AM, Bruce Edge
<br...@nextissuemedia.com> wrote:
> ...If I wanted to enable this behavior with a new format identifier (if that’s
> the right term for “tidy”, “infinity”, etc), ...

We call those "selectors".

> would this fit better as a ResourceDecorator or more like a new extension
> of SlingSafeMethodsServlet?...

That sounds like a new servlet that extends SlingSafeMethodsServlet
indeed, registered with a "hal" selector for example, so that
/foo.tidy.infinity.hal.json calls your variant. Would be a useful
contribution for Sling BTW.

That servlet might just use RequestDispatcher.include(...) to insert
the standard Sling JSON rendering in the right place - I haven't tried
that but it's easy to try, and if that doesn't work we could refactor
the JsonRendererServlet [1] to make the rendering part reusable.

-Bertrand

[1] https://svn.apache.org/repos/asf/sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/JsonRendererServlet.java

Re: HATEOAS compliant json self/child references from sling?

Posted by Bruce Edge <br...@nextissuemedia.com>.
OK, starting to make more sense I think. Thanks for clarifying the distinction of nodes vs data. By structure I’m referring to JCR nodes only, not the attached data.

If I wanted to enable this behavior with a new format identifier (if that’s the right term for “tidy”, “infinity”, etc), e.g.:
http://localhost:8090/var/content.hateoas.json<http://localhost:8090/var/content.infinity.json>
would this fit better as a ResourceDecorator or more like a new extension of SlingSafeMethodsServlet?

Retrieval of the actual data contents connected to each node is another story that I’m still getting me head around. Not going to pollute this thread with that aspect of it.

-Bruce

From: Jason Bailey <Ja...@sas.com>>
Reply-To: "users@sling.apache.org<ma...@sling.apache.org>" <us...@sling.apache.org>>
Date: Wednesday, November 12, 2014 at 11:50 AM
To: "users@sling.apache.org<ma...@sling.apache.org>" <us...@sling.apache.org>>
Subject: RE: HATEOAS compliant json self/child references from sling?

So when you say data structure you're talking about nodes in the jcr structure and their contents. Each node is wrapped in concept called a resource.

When you wrote the url earlier  http://localhost:8090/var/content.tidy.json  the underlying REST engine is finding the resource at the path /var/content/ which in this case is specifically a jcr node resource and then it's looking at the extension you're using and selecting an OSGi that renders that service. In this case there's a specific resource renderer that handles json and it's the renderer that is taking your request for that resource and returning the json object. You could actually get the entire tree that you are authorized to see with one call by using http://localhost:8090/var/content.infinity.json

More information at
http://sling.apache.org/documentation/the-sling-engine/architecture.html




-----Original Message-----
From: Bruce Edge [mailto:bruce.edge@nextissuemedia.com]
Sent: Wednesday, November 12, 2014 2:29 PM
To: users@sling.apache.org<ma...@sling.apache.org>
Subject: Re: HATEOAS compliant json self/child references from sling?

I must be missing some fundamental concept here.
I'm not sure exactly what you mean by "default json rendering of resources". I'm after structure data here, not actual content rendering.
I just want to be able to obtain self & child references in json responses so the UI can create the appropriate tree structure to navigate the JCR data.
The actual representation of the leaf node data will be specific to that data type and handled by the client UI.

-Bruce

From: Sarwar Bhuiyan <sa...@gmail.com>>
Reply-To: "users@sling.apache.org<ma...@sling.apache.org>" <us...@sling.apache.org>>
Date: Wednesday, November 12, 2014 at 11:20 AM
To: "users@sling.apache.org<ma...@sling.apache.org>" <us...@sling.apache.org>>
Subject: Re: HATEOAS compliant json self/child references from sling?

Bruce, it's not the format that's the problem. It's the default json rendering of resources that's the issue for things exposed to the public side. Typically what we do for the web side of things is either write our own servlets or component jsps where we can have more control of what to output.

On Wednesday, November 12, 2014, Bruce Edge <br...@nextissuemedia.com>>
wrote:

I can understand how exposing that level of structure may be a risk in some circumstances but it allows for a huge leg up on the client side code.
Things like https://github.com/GonzaloAlvarez/restangular-hateoas provide a superbly simple way to wrap a UI around the whole thing if you have HATEOAS on the server side. It's as close as you can get to a CRUD UI with seriously minimal code.
Also, this is the data format provided by spring-data-rest, so it's a format that already has wide acceptance.

I suppose one could enable this only for specific paths if security was a concern.

-Bruce

From: Jason Bailey <Ja...@sas.com> <javascript:;><mailto:
Jason.Bailey@sas.com<ma...@sas.com> <javascript:;>>>
Reply-To: "users@sling.apache.org<ma...@sling.apache.org> <javascript:;><mailto:
users@sling.apache.org<ma...@sling.apache.org> <javascript:;>>" <us...@sling.apache.org>
<javascript:;><mailto:users@sling.apache.org <javascript:;>>>
Date: Wednesday, November 12, 2014 at 11:05 AM
To: "users@sling.apache.org<ma...@sling.apache.org> <javascript:;><mailto:users@sling.apache.org
<javascript:;>>" <us...@sling.apache.org> <javascript:;><mailto:
users@sling.apache.org<ma...@sling.apache.org> <javascript:;>>>
Subject: RE: HATEOAS compliant json self/child references from sling?

Not unless you add it yourself. As a note, you may not want to design your application where you are relying on the default json renderer to supply information to the front end client. It can reveal more information and structure then a lot of people are comfortable with.

-----Original Message-----
From: Bruce Edge [mailto:bruce.edge@nextissuemedia.com <javascript:;>]
Sent: Wednesday, November 12, 2014 1:49 PM
To: users
Subject: HATEOAS compliant json self/child references from sling?

Can one retrieve HATEOAS format responses form sling?

%> curl -qu admin:admin http://localhost:8090/var/content.tidy.json
{
   "jcr:createdBy": "admin",
   "jcr:mimeType": "application/octet-stream",
   "jcr:created": "Sat Nov 08 2014 16:17:51 GMT-0800",
   "jcr:lastModified": "Sat Nov 08 2014 16:17:51 GMT-0800",
   "jcr:primaryType": "sling:Folder"
}

Using a HATEOAS server I would expect something like this:
{
   "jcr:createdBy": "admin",
   "jcr:mimeType": "application/octet-stream",
   "jcr:created": "Sat Nov 08 2014 16:17:51 GMT-0800",
   "jcr:lastModified": "Sat Nov 08 2014 16:17:51 GMT-0800",
   "jcr:primaryType": ³sling:Folder"
"_links":{
     "self":{
       "href":"http://localhost:8090/var/content"
     }
   }
}

Is it possible to have sling insert both self and child references into all json responses?

-Bruce






RE: HATEOAS compliant json self/child references from sling?

Posted by Jason Bailey <Ja...@sas.com>.
So when you say data structure you're talking about nodes in the jcr structure and their contents. Each node is wrapped in concept called a resource. 

When you wrote the url earlier  http://localhost:8090/var/content.tidy.json  the underlying REST engine is finding the resource at the path /var/content/ which in this case is specifically a jcr node resource and then it's looking at the extension you're using and selecting an OSGi that renders that service. In this case there's a specific resource renderer that handles json and it's the renderer that is taking your request for that resource and returning the json object. You could actually get the entire tree that you are authorized to see with one call by using http://localhost:8090/var/content.infinity.json  

More information at 
http://sling.apache.org/documentation/the-sling-engine/architecture.html




-----Original Message-----
From: Bruce Edge [mailto:bruce.edge@nextissuemedia.com] 
Sent: Wednesday, November 12, 2014 2:29 PM
To: users@sling.apache.org
Subject: Re: HATEOAS compliant json self/child references from sling?

I must be missing some fundamental concept here.
I'm not sure exactly what you mean by "default json rendering of resources". I'm after structure data here, not actual content rendering.
I just want to be able to obtain self & child references in json responses so the UI can create the appropriate tree structure to navigate the JCR data.
The actual representation of the leaf node data will be specific to that data type and handled by the client UI.

-Bruce

From: Sarwar Bhuiyan <sa...@gmail.com>>
Reply-To: "users@sling.apache.org<ma...@sling.apache.org>" <us...@sling.apache.org>>
Date: Wednesday, November 12, 2014 at 11:20 AM
To: "users@sling.apache.org<ma...@sling.apache.org>" <us...@sling.apache.org>>
Subject: Re: HATEOAS compliant json self/child references from sling?

Bruce, it's not the format that's the problem. It's the default json rendering of resources that's the issue for things exposed to the public side. Typically what we do for the web side of things is either write our own servlets or component jsps where we can have more control of what to output.

On Wednesday, November 12, 2014, Bruce Edge <br...@nextissuemedia.com>>
wrote:

I can understand how exposing that level of structure may be a risk in some circumstances but it allows for a huge leg up on the client side code.
Things like https://github.com/GonzaloAlvarez/restangular-hateoas provide a superbly simple way to wrap a UI around the whole thing if you have HATEOAS on the server side. It's as close as you can get to a CRUD UI with seriously minimal code.
Also, this is the data format provided by spring-data-rest, so it's a format that already has wide acceptance.

I suppose one could enable this only for specific paths if security was a concern.

-Bruce

From: Jason Bailey <Ja...@sas.com> <javascript:;><mailto:
Jason.Bailey@sas.com<ma...@sas.com> <javascript:;>>>
Reply-To: "users@sling.apache.org<ma...@sling.apache.org> <javascript:;><mailto:
users@sling.apache.org<ma...@sling.apache.org> <javascript:;>>" <us...@sling.apache.org>
<javascript:;><mailto:users@sling.apache.org <javascript:;>>>
Date: Wednesday, November 12, 2014 at 11:05 AM
To: "users@sling.apache.org<ma...@sling.apache.org> <javascript:;><mailto:users@sling.apache.org
<javascript:;>>" <us...@sling.apache.org> <javascript:;><mailto:
users@sling.apache.org<ma...@sling.apache.org> <javascript:;>>>
Subject: RE: HATEOAS compliant json self/child references from sling?

Not unless you add it yourself. As a note, you may not want to design your application where you are relying on the default json renderer to supply information to the front end client. It can reveal more information and structure then a lot of people are comfortable with.

-----Original Message-----
From: Bruce Edge [mailto:bruce.edge@nextissuemedia.com <javascript:;>]
Sent: Wednesday, November 12, 2014 1:49 PM
To: users
Subject: HATEOAS compliant json self/child references from sling?

Can one retrieve HATEOAS format responses form sling?

%> curl -qu admin:admin http://localhost:8090/var/content.tidy.json
{
   "jcr:createdBy": "admin",
   "jcr:mimeType": "application/octet-stream",
   "jcr:created": "Sat Nov 08 2014 16:17:51 GMT-0800",
   "jcr:lastModified": "Sat Nov 08 2014 16:17:51 GMT-0800",
   "jcr:primaryType": "sling:Folder"
}

Using a HATEOAS server I would expect something like this:
{
   "jcr:createdBy": "admin",
   "jcr:mimeType": "application/octet-stream",
   "jcr:created": "Sat Nov 08 2014 16:17:51 GMT-0800",
   "jcr:lastModified": "Sat Nov 08 2014 16:17:51 GMT-0800",
   "jcr:primaryType": ³sling:Folder"
"_links":{
     "self":{
       "href":"http://localhost:8090/var/content"
     }
   }
}

Is it possible to have sling insert both self and child references into all json responses?

-Bruce





Re: HATEOAS compliant json self/child references from sling?

Posted by Bruce Edge <br...@nextissuemedia.com>.
I must be missing some fundamental concept here.
I’m not sure exactly what you mean by “default json rendering of resources”. I’m after structure data here, not actual content rendering.
I just want to be able to obtain self & child references in json responses so the UI can create the appropriate tree structure to navigate the JCR data.
The actual representation of the leaf node data will be specific to that data type and handled by the client UI.

-Bruce

From: Sarwar Bhuiyan <sa...@gmail.com>>
Reply-To: "users@sling.apache.org<ma...@sling.apache.org>" <us...@sling.apache.org>>
Date: Wednesday, November 12, 2014 at 11:20 AM
To: "users@sling.apache.org<ma...@sling.apache.org>" <us...@sling.apache.org>>
Subject: Re: HATEOAS compliant json self/child references from sling?

Bruce, it's not the format that's the problem. It's the default json
rendering of resources that's the issue for things exposed to the public
side. Typically what we do for the web side of things is either write our
own servlets or component jsps where we can have more control of what to
output.

On Wednesday, November 12, 2014, Bruce Edge <br...@nextissuemedia.com>>
wrote:

I can understand how exposing that level of structure may be a risk in
some circumstances but it allows for a huge leg up on the client side code.
Things like https://github.com/GonzaloAlvarez/restangular-hateoas provide
a superbly simple way to wrap a UI around the whole thing if you have
HATEOAS on the server side. It’s as close as you can get to a CRUD UI with
seriously minimal code.
Also, this is the data format provided by spring-data-rest, so it’s a
format that already has wide acceptance.

I suppose one could enable this only for specific paths if security was a
concern.

-Bruce

From: Jason Bailey <Ja...@sas.com> <javascript:;><mailto:
Jason.Bailey@sas.com<ma...@sas.com> <javascript:;>>>
Reply-To: "users@sling.apache.org<ma...@sling.apache.org> <javascript:;><mailto:
users@sling.apache.org<ma...@sling.apache.org> <javascript:;>>" <us...@sling.apache.org>
<javascript:;><mailto:users@sling.apache.org <javascript:;>>>
Date: Wednesday, November 12, 2014 at 11:05 AM
To: "users@sling.apache.org<ma...@sling.apache.org> <javascript:;><mailto:users@sling.apache.org
<javascript:;>>" <us...@sling.apache.org> <javascript:;><mailto:
users@sling.apache.org<ma...@sling.apache.org> <javascript:;>>>
Subject: RE: HATEOAS compliant json self/child references from sling?

Not unless you add it yourself. As a note, you may not want to design your
application where you are relying on the default json renderer to supply
information to the front end client. It can reveal more information and
structure then a lot of people are comfortable with.

-----Original Message-----
From: Bruce Edge [mailto:bruce.edge@nextissuemedia.com <javascript:;>]
Sent: Wednesday, November 12, 2014 1:49 PM
To: users
Subject: HATEOAS compliant json self/child references from sling?

Can one retrieve HATEOAS format responses form sling?

%> curl -qu admin:admin http://localhost:8090/var/content.tidy.json
{
   "jcr:createdBy": "admin",
   "jcr:mimeType": "application/octet-stream",
   "jcr:created": "Sat Nov 08 2014 16:17:51 GMT-0800",
   "jcr:lastModified": "Sat Nov 08 2014 16:17:51 GMT-0800",
   "jcr:primaryType": "sling:Folder"
}

Using a HATEOAS server I would expect something like this:
{
   "jcr:createdBy": "admin",
   "jcr:mimeType": "application/octet-stream",
   "jcr:created": "Sat Nov 08 2014 16:17:51 GMT-0800",
   "jcr:lastModified": "Sat Nov 08 2014 16:17:51 GMT-0800",
   "jcr:primaryType": ³sling:Folder"
"_links":{
     "self":{
       "href":"http://localhost:8090/var/content"
     }
   }
}

Is it possible to have sling insert both self and child references into
all json responses?

-Bruce





Re: HATEOAS compliant json self/child references from sling?

Posted by Sarwar Bhuiyan <sa...@gmail.com>.
Bruce, it's not the format that's the problem. It's the default json
rendering of resources that's the issue for things exposed to the public
side. Typically what we do for the web side of things is either write our
own servlets or component jsps where we can have more control of what to
output.

On Wednesday, November 12, 2014, Bruce Edge <br...@nextissuemedia.com>
wrote:

> I can understand how exposing that level of structure may be a risk in
> some circumstances but it allows for a huge leg up on the client side code.
> Things like https://github.com/GonzaloAlvarez/restangular-hateoas provide
> a superbly simple way to wrap a UI around the whole thing if you have
> HATEOAS on the server side. It’s as close as you can get to a CRUD UI with
> seriously minimal code.
> Also, this is the data format provided by spring-data-rest, so it’s a
> format that already has wide acceptance.
>
> I suppose one could enable this only for specific paths if security was a
> concern.
>
> -Bruce
>
> From: Jason Bailey <Jason.Bailey@sas.com <javascript:;><mailto:
> Jason.Bailey@sas.com <javascript:;>>>
> Reply-To: "users@sling.apache.org <javascript:;><mailto:
> users@sling.apache.org <javascript:;>>" <users@sling.apache.org
> <javascript:;><mailto:users@sling.apache.org <javascript:;>>>
> Date: Wednesday, November 12, 2014 at 11:05 AM
> To: "users@sling.apache.org <javascript:;><mailto:users@sling.apache.org
> <javascript:;>>" <users@sling.apache.org <javascript:;><mailto:
> users@sling.apache.org <javascript:;>>>
> Subject: RE: HATEOAS compliant json self/child references from sling?
>
> Not unless you add it yourself. As a note, you may not want to design your
> application where you are relying on the default json renderer to supply
> information to the front end client. It can reveal more information and
> structure then a lot of people are comfortable with.
>
> -----Original Message-----
> From: Bruce Edge [mailto:bruce.edge@nextissuemedia.com <javascript:;>]
> Sent: Wednesday, November 12, 2014 1:49 PM
> To: users
> Subject: HATEOAS compliant json self/child references from sling?
>
> Can one retrieve HATEOAS format responses form sling?
>
> %> curl -qu admin:admin http://localhost:8090/var/content.tidy.json
> {
>   "jcr:createdBy": "admin",
>   "jcr:mimeType": "application/octet-stream",
>   "jcr:created": "Sat Nov 08 2014 16:17:51 GMT-0800",
>   "jcr:lastModified": "Sat Nov 08 2014 16:17:51 GMT-0800",
>   "jcr:primaryType": "sling:Folder"
> }
>
> Using a HATEOAS server I would expect something like this:
> {
>   "jcr:createdBy": "admin",
>   "jcr:mimeType": "application/octet-stream",
>   "jcr:created": "Sat Nov 08 2014 16:17:51 GMT-0800",
>   "jcr:lastModified": "Sat Nov 08 2014 16:17:51 GMT-0800",
>   "jcr:primaryType": ³sling:Folder"
> "_links":{
>     "self":{
>       "href":"http://localhost:8090/var/content"
>     }
>   }
> }
>
> Is it possible to have sling insert both self and child references into
> all json responses?
>
> -Bruce
>
>
>

Re: HATEOAS compliant json self/child references from sling?

Posted by Bruce Edge <br...@nextissuemedia.com>.
I can understand how exposing that level of structure may be a risk in some circumstances but it allows for a huge leg up on the client side code. Things like https://github.com/GonzaloAlvarez/restangular-hateoas provide a superbly simple way to wrap a UI around the whole thing if you have HATEOAS on the server side. It’s as close as you can get to a CRUD UI with seriously minimal code.
Also, this is the data format provided by spring-data-rest, so it’s a format that already has wide acceptance.

I suppose one could enable this only for specific paths if security was a concern.

-Bruce

From: Jason Bailey <Ja...@sas.com>>
Reply-To: "users@sling.apache.org<ma...@sling.apache.org>" <us...@sling.apache.org>>
Date: Wednesday, November 12, 2014 at 11:05 AM
To: "users@sling.apache.org<ma...@sling.apache.org>" <us...@sling.apache.org>>
Subject: RE: HATEOAS compliant json self/child references from sling?

Not unless you add it yourself. As a note, you may not want to design your application where you are relying on the default json renderer to supply information to the front end client. It can reveal more information and structure then a lot of people are comfortable with.

-----Original Message-----
From: Bruce Edge [mailto:bruce.edge@nextissuemedia.com]
Sent: Wednesday, November 12, 2014 1:49 PM
To: users
Subject: HATEOAS compliant json self/child references from sling?

Can one retrieve HATEOAS format responses form sling?

%> curl -qu admin:admin http://localhost:8090/var/content.tidy.json
{
  "jcr:createdBy": "admin",
  "jcr:mimeType": "application/octet-stream",
  "jcr:created": "Sat Nov 08 2014 16:17:51 GMT-0800",
  "jcr:lastModified": "Sat Nov 08 2014 16:17:51 GMT-0800",
  "jcr:primaryType": "sling:Folder"
}

Using a HATEOAS server I would expect something like this:
{
  "jcr:createdBy": "admin",
  "jcr:mimeType": "application/octet-stream",
  "jcr:created": "Sat Nov 08 2014 16:17:51 GMT-0800",
  "jcr:lastModified": "Sat Nov 08 2014 16:17:51 GMT-0800",
  "jcr:primaryType": ³sling:Folder"
"_links":{
    "self":{
      "href":"http://localhost:8090/var/content"
    }
  }
}

Is it possible to have sling insert both self and child references into all json responses?

-Bruce



RE: HATEOAS compliant json self/child references from sling?

Posted by Jason Bailey <Ja...@sas.com>.
Not unless you add it yourself. As a note, you may not want to design your application where you are relying on the default json renderer to supply information to the front end client. It can reveal more information and structure then a lot of people are comfortable with. 

-----Original Message-----
From: Bruce Edge [mailto:bruce.edge@nextissuemedia.com] 
Sent: Wednesday, November 12, 2014 1:49 PM
To: users
Subject: HATEOAS compliant json self/child references from sling?

Can one retrieve HATEOAS format responses form sling?

%> curl -qu admin:admin http://localhost:8090/var/content.tidy.json
{
  "jcr:createdBy": "admin",
  "jcr:mimeType": "application/octet-stream",
  "jcr:created": "Sat Nov 08 2014 16:17:51 GMT-0800",
  "jcr:lastModified": "Sat Nov 08 2014 16:17:51 GMT-0800",
  "jcr:primaryType": "sling:Folder"
}

Using a HATEOAS server I would expect something like this:
{
  "jcr:createdBy": "admin",
  "jcr:mimeType": "application/octet-stream",
  "jcr:created": "Sat Nov 08 2014 16:17:51 GMT-0800",
  "jcr:lastModified": "Sat Nov 08 2014 16:17:51 GMT-0800",
  "jcr:primaryType": ³sling:Folder"
 "_links":{
    "self":{
      "href":"http://localhost:8090/var/content"
    }
  }
}

Is it possible to have sling insert both self and child references into all json responses?

-Bruce