silkapp / rest

Packages for defining APIs, running them, generating client code and documentation.

Home Page:http://silkapp.github.io/rest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pretty-print JSON output

thomasvnoort opened this issue · comments

It would be great if there would be a way to instruct rest to pretty-print JSON output. Many web services offer this by passing a pretty query parameter. I understand that this will reserve a name, so it should definitely be optional and configurable.

Sounds good! Note that if you're on the command line, you can pipe your output through e.g. python -m json.tool or something like jq. Browsers generally also pretty-print json in their debuggers. What's your use case for this?

It's just a matter of convenience. I use Safari mostly and I don't think I can get Safari to pretty-print, but having a query parameter saves me from opening the debugger all the time anyway. Also, I use curl a lot and I can pipe it through some pretty-printer indeed. However, any output that is not JSON will fail in the pretty-printer with a weird error message. Then I have to think about getting curl to also print the error code somewhere, etc. Having a pretty query parameter makes life just a little bit easier :)

I'll look into this.

Can you better explain what you would like to see? I'm not sure I'm quite getting it.

@thomasvnoort is on vacation...

We discussed it a bit. We would like something that adds a pretty parameter (name might be customizable) to every end point with json output.

One idea is to have prettyJsonO/prettyXmlO combinators. When writing an api you can make sure to just use that instead of the normal combinators. I think this needs #20. This means you could forget it, but in practice you can have a re-export module that only exposes the combinators you want to us.

Another way is to implement it directly in the driver, that could be done right now. It would require some way to configure this, probably a parameter to apiToHandler. This would apply it to all matching handlers.