Netflix/feign — pull request #59 by davidmc24 (2013-08-30 03:58:38+00:00)
Title: add RequestEncoder/ResponseDecoder interfaces (#53)

This is intended as a step towards simplifying Feign, by allowing the
removal of the Encoder/Decoder interfaces in a future version.

This is a first attempt; all comments welcome. I started out trying Adrian's suggestion of having a single Codec type, but ended up having two types instead. I didn't like having to provide a no-op implementation of encode if I only care about decoding, or decode if I only cared about encoding. It also would have somewhat complicated the implementation of backwards-compatibility adapter classes.

I haven't yet touched form encoders. My guess is that they will want to remain as a separate thing, and perhaps cut their dependency on the Encoder.Text type.

In introducing the new interfaces, I was keeping in mind that at some point, we'll want to add support for binary bodies. For ResponseDecoder, that means that the method now takes a Response as the parameter. This allows access to the body as a reader right now, and it would be easy to add access to the body as an InputStream or something similar later. It also has the potentially interesting side effect of allowing using headers as part of the decoding. For RequestEncoder, I currently have the return value as byte[]. Since the rest of the library hasn't yet been retrofitted to support binary bodies, that means that there's currently a couple extra String encode/decodes that don't serve much value. I'm not convinced that returning a byte[] is necessarily the right direction here. Passing the RequestTemplate to allow filling in the body might be a better approach, and allow easy extension to supporting binary content when it's ready.