Stefan Tilkov wrote:
> FWIW, here's what Rails does:
>
> def add
> company = params[:person].delete(:company)
> @company = Company.find_or_create_by_name(company[:name])
> @person = @company.people.create(params[:person])
>
> respond_to do |wants|
> wants.html { redirect_to(person_list_url) }
> wants.js
> wants.xml { render :xml => @person.to_xml(:include => @company) }
> end
> end
>
> Of course it's hard to translate all of the Ruby syntactic sugar
> (blocks, method_missing hacks etc.) to Java, but the main different is
> that in RoR, I can have a single method that returns different
> representations. In my method, I don't even care whether it's the
> Accept: header or the extension that was used to select the content type.
>
Thanks, that was really useful. So RoR has a mapping between media types
and prefixes to handle things uniformly. I sort of baulk at this type of
mapping cause '.xml' so vague and MIME types are there for a good reason.
Anyway, as you say whether it's good or bad the pattern (i think it an
anti-pattern!) we need to have some viable and non-to-verbose reusable
answer to the question you ask.
Maybe we could do something like:
@UriTemplate("{id}")
class Customer {
@HttpMethod
@ProduceMime("application/xml", "application/json")
@SuffixeAntiPattern("application/xml", ".xml",
"application/json", ".js")
Response get() { ... }
}
However, I would still prefer a pattern using URI templates and saying
this is how it can be done but we do not encourage you to use this pattern.
Paul.
--
| ? + ? = To question
----------------\
Paul Sandoz
x38109
+33-4-76188109