dev@jsr311.java.net

Re: Content Negotation vs. Extensions

From: Stefan Tilkov <stefan.tilkov_at_innoq.com>
Date: Thu, 26 Apr 2007 17:55:08 +0200

On Apr 26, 2007, at 5:47 PM, Paul Sandoz wrote:

> 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() { ... }
> }
>

This looks extremely ugly - but maybe that was your intention :-)

In all fairness, RoR doesn't quite have a simple mapping from media
types to suffixes, it's just something Rails' pretty powerful routing
engine can enable. I can elaborate on this if someone cares - I'm not
sure it's that relevant.

Stefan


> 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_jsr311.dev.java.net
> For additional commands, e-mail: dev-help_at_jsr311.dev.java.net
>