Support recursive path handling


#1

Hi RAML Community,
I use a recursive sub-resource path at my API, developed with JAX-RS. Because I can’t explain it better than showing an example, here is the example URI:

/widget/1212/subwidget/17/component/3414

or

/widget/1212/subwidget/17/subwidget/18/subwidget/19/component/3414

so subwidget/{sub_id} can repeat a few times. The recursion works correctly.

Is there any way to describe this in RAML ?

Thanks for reply.
Chris (Germany)


#2

I’m not an expert here, but personally I don not recall seeing anything in the RAML spec that would allow for such constructs.

Just curious though: how do you model that in JAX-RS?


#3

First of all… I am unclear how that is RESTful? By that I mean… why are you using paths to specify multiple widgets? In your 2nd example, is subwidget/19 a child of the collection found at subwidget/18? I guess it could be REST like…but it seems kind of odd to have such long URL paths that don’t seem to follow any normal pattern I’ve seen in REST APIs.

I am also curious how you handle it in your JAX-RS annotations? I was not aware that JAX-RS supported any sort of repeating pattern handling like that? Do you have some sort of path like {*} that you then parse the incoming path yourself in your method?


#4

Hi michael, thanks for your reply.

I agree with that. Therefore I leave this question here to see if anyone knows a way to do that.

I use the JAX-RS reference implementation Jersey 2.0. You can do it this way:

public class SomeResource{
...    
@Path("widget/{widgetNr}")
    public SubResource getSubResource(...){
        return new SubResource(...);
    }
...
}

public class SubResource{
    ...
    @Path("subwidget/{subwidgetNr}")
    public SubResource getSubResource(...){
        SubResource subResource = this;
        return subResource;
    }
    @Path("component/{compNr}")
    public CompResource getComponent(...){...}
}

As I sad, it’s only an example and not a snippet of my code. Hope it’s comprehensible.


#5

Hi justjackson, thanks for your reply and criticism.

I didn’t say that this recursive construct in the example is completely RESTful. As I sad to michael, it’s only an example to describe my question - not a snippet of the code of my project. I think there are some use cases to put this in a correct and RESTful use, but I won’t discuss this here in the RAML Forum.

My question still requires an answer.

See my reply to michaels post.


#6

Interesting. Wasn’t aware that such an approach would work with JAX-RS.

Unfortunately, I cannot help you with the RAML part. I hope someone else will.

In general, I do think that support for such recursive paths might be useful in some situations. Maybe support can be considered for future RAML versions, in case it is not there yet?


#7

Unless there is something I missed… there is no way to define a repeating path pattern as you have modeled in JAX-RS in RAML. I wasn’t try to criticize, more specifically I think RAML models REST and as far as I can tell there isn’t a restful approach to what you are describing… but then, REST is open to speculation hence no standard behind it… so perhaps what you are doing is REST in some way, just not the typical way most people describe it. :slight_smile: Hope that redeems my criticism.