Kashyap Kashyap - 2 months ago 17
YAML Question

Can/should I use YAML as payload in RESTful webservice?

As the header says.

In general I like YAML more than JSON these days. I implemented a RESTful WS PoC back in teh day using JSON. I was wondering if I can instead use YAML or not.

E.g. are there enough tools/libraries/support for doing that? Or would I end up doing quite a bit of mundane/tedious coding which I would've avoided if I were using JSON instead?

Also as I understood from WWW: REST doesn't restrict one from using YAML as the payload, is that correct?

Thanks!

Answer

Yes, if it's a goal that the data be especially readable to humans. There's not a lot to gain here for webservices however, which represent app to app communication. Computers don't care, and JSON can be pretty-printed to improve legibility somewhat. REST itself isn't focused on protocols/formats so much as patterns.

YAML is well supported by mainstream languages, though not always included in standard libraries as JSON typically is. So you'll probably be looking at an additional library dependency. Also, if the client is a browser, parsing will be slower, as you'll have to use a non-native external lib such as described here using: JavaScript YAML Parser .

I could imagine some use as a debug parameter, perhaps …?fmt=yaml to assist during development.