2

I have a Rails endpoint that redirects with url parameters.

The code is really simple:

def success_redirect
  redirect_to "#{success_url}/#{encoded_params}"
end

My colleague hopes I could make the same redirect, but send parameters as JSON instead.

Is it possible to do this? Somehow I can't find any resources on the topic, which seems unusual.

7
  • What is the request type you are trying to make (GET/POST/PUT/PATCH)?
    – MrShemek
    Mar 21, 2019 at 13:43
  • It's a GET request, and I can't really affect that, because there is a round trip to another service. Mar 21, 2019 at 13:45
  • The GET request does not have body. You can send JSON as query params or in the headers. Where the JSON is expected (according to the endpoint documentation)?
    – MrShemek
    Mar 21, 2019 at 13:47
  • Another strange question will follow: Can I do a POST redirect from GET action? Probably not? Mar 21, 2019 at 14:01
  • 1
    To answer your question: stackoverflow.com/questions/985596/…
    – MrShemek
    Mar 21, 2019 at 14:06

1 Answer 1

1

Short answer - it is not possible.

When you are using redirect_to, Rails sets status header to 302 and location header with to the URL you want to reach. Then, the browser interprets this response and redirects you.

Also, for GET request, it is possible (IMO, not recommended) to include a body (your JSON payload). However, not in Rails.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.