[Catalyst] Re: charset not needed for Catalyst::Action::REST?

Bill Moseley moseley at hank.org
Sat Feb 25 08:38:16 GMT 2012


Ok, while trying to dig a bit more on Content-Type in RESTful services, I
came across this blog entry, although it is mostly about versioning.

http://thereisnorightway.blogspot.com/2011/02/versioning-and-types-in-resth=
ttp-api.html

He's suggesting a vender specific Content-Type that includes a version
number.  Frankly, that sounds like a nightmare to maintain
(and certainly not in the same Catalyst app).  The argument for the
vender-specific Content-Type is that application/json could mean return any
json.  But, I think it's enough of a contract that they are connecting to
my web service to know that the json returned MUST be specific to my
service.

Anyone using vender-specific Content-Type headers as he suggests?

Anyone have suggestions on the charset question below?


I've asked a few times about API versioning (including how to have
Controller actions inherit from each other).   And I'm now of the opinion
that it's just a bad idea and I've decided to use the common three digit
version and return it in an X-Version response header.  If the first
"major" digit changes it means the API is backwards incompatible and I'll
use a new hostname or header for the load balancer to dispatch on.




On Fri, Feb 24, 2012 at 10:50 PM, Bill Moseley <moseley at hank.org> wrote:

> When using Catalyst::Action::REST the content-type response never includes
> a charset.  JSON seems to be handled correctly in code -- JSON strings are
> always UTF-8.  Does that mean there is no need to specify a charset on
> responses?
>
> And what if a JSON request comes in with a non-UTF8 charset?  Should that
> be ignored?  It's application/json, not text/json so maybe there no
> encoding issues?
>
> What about other serializations?  YAML is UTF-8 or UTF-16.  Does that mean
> the charset needs to be included in response?  And again, if a request
> comes in with UTF-16 does it need to be decoded or does that happen in
> YAML::Syck?
>
> Event text/html doesn't include a charset in a the "serialized" response.
>
>
> Does there need to be an additional decoding and encoding layer when using
> Catalyst::Action::REST?   Should I force a charset on all responses?
>
>
> BTW -- doesn't seem like YAML survies a round trip like JSON does:
>
> As expected:
>
> $ perl -MEncode -wle '$x =3D "\x{263A}"; print length( $x )'
> 1
>
> $ perl -MEncode -wle '$x =3D Encode::encode_utf8("\x{263A}"); print lengt=
h(
> $x )'
> 3
>
>
> And also as expected:
>
>
> $ perl -MJSON  -MEncode -wle 'print
> length(JSON::decode_json(JSON::encode_json( ["\x{263A}"]) )->[0])'
> 1
>
>
> But YAML drops the utf8 flag:
>
> $ perl -MYAML::Syck  -MEncode -wle 'print
> length(YAML::Syck::Load(YAML::Syck::Dump( ["\x{263A}"]) )->[0])'
> 3
>
>
>
>
> --
> Bill Moseley
> moseley at hank.org
>



-- =

Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20120225/73c44=
e82/attachment.htm


More information about the Catalyst mailing list