You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ralph Mack <ra...@comcast.net> on 2012/03/08 23:10:22 UTC

Does REST plugin support complex RESTful URLs?

The REST plugin seems to address the vanilla cases of restful URLs:

- /hair/bears/furbolg
- /hair/bears/furbolg/1

or even my preferred form

- /hair/bears/furbolg/firbolg-1

If I have a FurbolgController (or FurbolgAction) and define the right
methods, it works like magic.

However, following the RESTFul logic of having sensible URLs for every
useful resource, how can I use it for a put to, say, replace a certain
field only of all the items of interest in a range or set of ranges:

- /hair/bears/furbolg/12-14+16-18/coat-color

It seems to me I should be able to specify the single value in quotes as
the JSON body for that one and pass it to my business logic rather than
having to operate at the record level and truck around all the data I
don't care about to do the field-level updates. The example is contrived
but field-level updates are useful in edit-in-place AJAX scenarios.

I know I can coax anything I want out of Spring MVC for this kind of
job. It allows for arbitrary mappings from URL elements to controller
method parameters when matching URLs to controllers and methods (similar
to ASP.NET MVC, well, vice versa really). How would I do it in Struts?
Am I beyond the capabilities of the REST plugin? Outside the vibe?

I checked the list archives for the past year and looked at the examples
on the web but didn't see anything that looked like it had the potential
to address this. However, Struts is a very clever framework and maybe
the pieces of the solution are sitting in front of me and I just haven't
recognized where they fit together. Anybody want to clue me in?

Ralph



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Does REST plugin support complex RESTful URLs?

Posted by lupestro <ra...@comcast.net>.
> I checked the list archives for the past year and looked at the examples 
> on the web but didn't see anything that looked like it had the potential 
> to address this. 

OK - I dug further (using nabble this time) and found the discussion from
July 2008 where Jeromy Evans sketched an approach for URIs of the form
book/1/chapter/3:

>  1. enable the NamedVariablePatternMatcher via struts.xml 
>  2. Create the BookController in the root namespace.  GET /book/123 will 
> invoke BookController.show() with id=123 
> 3. Create the ChapterController in the namespace containing the book id 
> variable (/book/{bookid}). GET /book/123/chapter will invoke 
> ChapterContoller.index() with bookId=123. 
> [...]
> @Namespace("/") 
> public class BookController implements ModelDriven<Book> {  } 
>
> @Namespace("/book/{bookId}") 
> public class ChapterController implements ModelDriven<Chapter> {  } 

Unfortunately, his sample has gone missing over the years, but I can follow
the breadcrumbs from the snippet above.

That discussion also had a lively side-discussion on what is or is not
RESTful. I will readily admit that the multi-selection of resources implied
by the following isn't RESTful.

- /hair/bears/furbolg/12-14+16-18/coat-color 

However, the following unambiguous field identification is RESTful:

- /hair/bears/furbolg/12/coat-color is, 

so that is the problem that I will address and leave the multi-select case
behind. However, Jeromy's approach has me creating a class for each field I
wish to support, which seems awkward, and then I'm not sure I can do PUTs
without a follow-on ID after the field name. Is there a good way around
this?

Is Jeromy's approach still the plan of record or has something been
introduced since then that is more akin to what Rails, Spring MVC, and
ASP.NET MVC do? I know it would be easy with that sort of annotation.

Ralph


--
View this message in context: http://struts.1045723.n5.nabble.com/Does-REST-plugin-support-complex-RESTful-URLs-tp5549042p5549581.html
Sent from the Struts - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org