You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Fabian Christ <ch...@googlemail.com> on 2013/03/27 18:37:11 UTC

Use placeholders in paths - RESTful API

Hi,

in current REST API framework approaches you can specify a path to a
resource with placeholders and use the concrete values of those in
your code, like this

@Path(/customers/{customerid}/bills/{billid}/amount)

Is something similar possible in Sling? I understand the concept of
node types and resource types. I have also seen the example of
path-based-rtp (for resource type processing?). But I could not find
an example for the situation above.

Best,
 - Fabian

--
Fabian
http://twitter.com/fctwitt

Re: Use placeholders in paths - RESTful API

Posted by Sarwar Bhuiyan <sa...@gmail.com>.
Good question. Have a look at the example of the @SlingServlet annotation
which can take in a paths property inside it (e.g.
http://blogs.adobe.com/aaa/2012/09/cq-tips-and-tricks-1-how-to-define-a-slingservlet-cq5-5-5-6.html
)

However, it doesn't support placeholders. So what you may be able to do is
to put the initial part of the path , say /customers/ and then do the
processing after that. The other option is to write your own
ResourceProvider which would handle the /customers/ prefix and then would
decide which handler to delegate it to based on the rest of the URL
structure.

In the default jcr based resource resolution, the other option could be
that your JCR node hierarchy is created as you showed in the URL.

/content/
 /customers/



On Wed, Mar 27, 2013 at 5:37 PM, Fabian Christ <christ.fabian@googlemail.com
> wrote:

> Hi,
>
> in current REST API framework approaches you can specify a path to a
> resource with placeholders and use the concrete values of those in
> your code, like this
>
> @Path(/customers/{customerid}/bills/{billid}/amount)
>
> Is something similar possible in Sling? I understand the concept of
> node types and resource types. I have also seen the example of
> path-based-rtp (for resource type processing?). But I could not find
> an example for the situation above.
>
> Best,
>  - Fabian
>
> --
> Fabian
> http://twitter.com/fctwitt
>

Re: Use placeholders in paths - RESTful API

Posted by Fabian Christ <ch...@googlemail.com>.
2013/3/27 Sarwar Bhuiyan <sa...@gmail.com>:
> /content/
>  /customers/
>   /1234/
>    /bills/
>      /b1234
>        /
>
> Each node level could have a resourceType property which would point to the
> script that'd render that. That script could easily query the path
> (currrentNode.getPath()) and extract the relevant bit fo data to do lookups
> and then rendering.

Nice ;) I came up with the same idea while thinking about it this afternoon.

Thanks for the helpful answer!


--
Fabian
http://twitter.com/fctwitt

Re: Use placeholders in paths - RESTful API

Posted by Sarwar Bhuiyan <sa...@gmail.com>.
Good question. Have a look at the example of the @SlingServlet annotation
which can take in a paths property inside it (e.g.
http://blogs.adobe.com/aaa/2012/09/cq-tips-and-tricks-1-how-to-define-a-slingservlet-cq5-5-5-6.html
)

However, it doesn't support placeholders. So what you may be able to do is
to put the initial part of the path , say /customers/ and then do the
processing after that. The other option is to write your own
ResourceProvider which would handle the /customers/ prefix and then would
decide which handler to delegate it to based on the rest of the URL
structure.

In the default jcr based resource resolution, the other option could be
that your JCR node hierarchy is created as you showed in the URL.

/content/
 /customers/
  /1234/
   /bills/
     /b1234
       /

Each node level could have a resourceType property which would point to the
script that'd render that. That script could easily query the path
(currrentNode.getPath()) and extract the relevant bit fo data to do lookups
and then rendering. This way, somebody could get /content/customers.json or
/content/customers/1234.json and that would get delegated to the correct
script or servlet by Sling.

Hope this helps somewhat.

Sarwar


On Wed, Mar 27, 2013 at 5:37 PM, Fabian Christ <christ.fabian@googlemail.com
> wrote:

> Hi,
>
> in current REST API framework approaches you can specify a path to a
> resource with placeholders and use the concrete values of those in
> your code, like this
>
> @Path(/customers/{customerid}/bills/{billid}/amount)
>
> Is something similar possible in Sling? I understand the concept of
> node types and resource types. I have also seen the example of
> path-based-rtp (for resource type processing?). But I could not find
> an example for the situation above.
>
> Best,
>  - Fabian
>
> --
> Fabian
> http://twitter.com/fctwitt
>