liberator icon indicating copy to clipboard operation
liberator copied to clipboard

retain original handler result in metadata.

Open xsc opened this issue 10 years ago • 3 comments

Summary

This MR would add the key :liberator/value - containing the original/raw value - to responses generated by run-handler.

Reason

To be able to verify response bodies (e.g. against a schema) one currently has to decode the content-negotiated-and-then-encoded data that Liberator resources produce (which is neither pretty nor always easily feasible). Alternatively, one can use ring-response to override the body, resulting in losing the value that the content negotiation provides.

Performing verification on the raw value seems reasonable and could be facilitated using the proposed changes.

xsc avatar Mar 03 '15 12:03 xsc

Actually, retaining values not only for ring-response might be desirable. Let me know what you think.

xsc avatar Mar 03 '15 12:03 xsc

I like the general idea but I have two things to add:

  • why not putting the "value" into the response map at :liberator/value instead of the meta-data. I think it would be more accessible. However there might my drawback because it's always "visible", e.g. when logging the response etc.
  • the add the value only for RingResponse. I think we should enable this for every value that is returned from a handler. I.e. associate the original value to the response (or response meta) in run-handler.

ordnungswidrig avatar Mar 03 '15 15:03 ordnungswidrig

I pushed an alternative approach as f21a2524aa51500b166cc67015c76c9fc98b1480, attaching the raw value to every response in run-handler, albeit still in the metadata since it would cause tests to fail otherwise. I can move it into the response map itself but I'm not sure whether this information is useful enough to warrant that.

On another note: Is :liberator/value the right name for this? Also, I'm not sure where a test for this would belong, so I'd be glad for any pointers. :)

xsc avatar Mar 03 '15 16:03 xsc