multiverse
multiverse copied to clipboard
Whats the best way to mutate request and response?
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 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 tofirst_name
andlast_name
and then write that back toconn
. - 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.