multiverse icon indicating copy to clipboard operation
multiverse copied to clipboard

Whats the best way to mutate request and response?

Open tanweerdev opened this issue 3 years ago • 1 comments

its not clear from the docs or readme whats the best way to mutate response in response_handler. can someone please guide me or add this in README. thanks

tanweerdev avatar Apr 12 '21 10:04 tanweerdev

@tanweerdev it depends on what your API is using and what compatibility issue the gate should fix.

For example, if you had just name parameter and then started using first_name and last_name then the gate should map those back. In request gate, you want to read conn params and change them so that:

  • add something like [first_name, last_name] = String.split(name, " ") and then write that to first_name and last_name and then write that back to conn.
  • remove old field name;

For the response gate you would match on connection routes and for those that are returning first_name and last_name separately you would take response body, decode it, do reverse operation (create new name = first_name <> " " <> last_name) and write it back to response body.

It's very hard to give you anything better than very abstract ideas because every gate is unique.

AndrewDryga avatar Apr 14 '21 15:04 AndrewDryga