silkapp / rest

Packages for defining APIs, running them, generating client code and documentation.
http://silkapp.github.io/rest
390 stars 52 forks source link

Raw json #146

Closed bergmark closed 8 years ago

bergmark commented 8 years ago

A first stab at allowing I/O of raw json bytestrings.

The first commit adds rawJsonI/O that behaves like rawXmlI/O, they cannot be combined with other dictionaries.

The second commit adds the RawJsonAndXmlI/O combinations. Ideally it would suffice to say rawXmlO . rawJsonO but since both take a ByteString handlers using this needs to return a tuple so the driver can choose which to send. Similarily with rawJsonAndXmlI; here we need to accept ByteStrings in two different formats which translates to the handler getting an Either as input.

It seems like solving this in a more proper way would be a lot of work of unknown complexity since this is orthogonal from how other dictionaries combine. Is this ok as an initial version?

Another undecided point is whether to use Either ByteString ByteString and (ByteString, ByteString). I'm leaning towards newtyping both to make it a bit less error-prone to pick the right bytestring.

hesselink commented 8 years ago

This looks great, I think it's the best we can do without a complete dictionary rewrite. It's sad the RawJsonAndXml stuff can't reuse the individual parts, but until we fix #20 I don't think we can easily improve this.

bergmark commented 8 years ago

Sweet.

I'll add the newtypes so the signatures become something like Either Json Xml and (Json, Xml) and I'll merge once I have tested it properly.

hesselink commented 8 years ago

Sounds good!

bergmark commented 8 years ago

I'm reconsidering the (Json, Xml) type for output. The ByteStrings are lazy which is good, but in my use case i currently need to do one http request for each result so it's wasteful. Perhaps it should be changed to callback style Either Json Xml -> m ByteString to avoid this.

hesselink commented 8 years ago

Yeah, that sounds like a more efficient format, good idea.