Output Encoding

41 views
Skip to first unread message

Indu

unread,
Sep 24, 2012, 4:33:05 AM9/24/12
to api-...@googlegroups.com
Hi all,

       I m developing RESTful web services in which the whole client is built upon the APIs provided and the client is completely stateless. Got into a big dilemma whether to provide the output encoding in the JSON response of the resource or not

Thanks for looking into this.

Thanks
Indu

Raghuveer Rao

unread,
Sep 24, 2012, 11:11:34 AM9/24/12
to api-...@googlegroups.com
You are building a service. This service can be potentially used by multiple clients. 
Rest allows clients to negotiate the format in which they want the output.
This is done by the request header / response header.

Raghu

slam

unread,
Sep 24, 2012, 11:20:57 AM9/24/12
to api-...@googlegroups.com
If encoding is in the JSON response, how can you read the JSON to know what encoding to use?

It's a catch 22. http://en.wikipedia.org/wiki/Catch-22_%28logic%29

Also, being restful means that the communication concerns are abstracted over a communication layer (ie: http in you case), and the api concerns is to provides information about the resource.

I think you should use the http headers to specify your encoding. exemple: Content-Type: application/json; charset=utf-8

That's in an ideal world. You don't give much information on your context, so maybe our friend the "real world" can make the final decision different.
JF


On Monday, September 24, 2012 4:33:05 AM UTC-4, Indu wrote:

Steve Klabnik

unread,
Sep 24, 2012, 11:36:05 AM9/24/12
to api-...@googlegroups.com
As I said in the other thread, JSON is UTF-8, 16, or 32. Section 3:
http://www.ietf.org/rfc/rfc4627.txt

JSON text SHALL be encoded in Unicode. The default encoding is
UTF-8.

Since the first two characters of a JSON text will always be ASCII
characters [RFC0020], it is possible to determine whether an octet
stream is UTF-8, UTF-16 (BE or LE), or UTF-32 (BE or LE) by looking
at the pattern of nulls in the first four octets.
Reply all
Reply to author
Forward
0 new messages