Kevin Wiggen
unread,Sep 7, 2012, 10:19:13 PM9/7/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to api-...@googlegroups.com
We are developing an API that is REST based with JSON payloads. Like many APIs, a number of the fields that can be set/retrieved are text based and can represent user content. Are their any best practices for how I should encode this information when passing it to a client.
Note that none of this information is meant to be HTML based, but I can't control what someone might do with my API, and many customer/partners will most likely build a HTML frontend with my data. Thus it would be possible for someone to give me a string that contains "<b>Kevin</b>" My backend does not care, but a HTML based API consumer who isn't careful might not like the information I am passing them unless they are careful and properly escape all of my information.
I could take the high road and claim that I am client agnostic and tell people to be careful with the data I am passing, but I can also see someone claiming my server is unsafe if I pass unescaped characters in my JSON responses.
For instance when I type <b>Kevin</b> into facebook, their api returns - "message": "\u003Cb>Kevin\u003C/b>", in the JSON payload.
Best practices???
Thanks,
Kevin