Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whats the best way to mutate request and response? #16

Open
tanweerdev opened this issue Apr 12, 2021 · 1 comment
Open

Whats the best way to mutate request and response? #16

tanweerdev opened this issue Apr 12, 2021 · 1 comment

Comments

@tanweerdev
Copy link

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

@AndrewDryga
Copy link
Member

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants