I want to have a GET route that will query an API to collect data, and then redirect to a POST with that data to save to the DB. For example:
get '/query/twitter/company/:name' do
get_number_of_tweets_for_day( params[:name] )
end
POST '/company/tweets/' do
company.tweets.create(:date => time_now, :count => num_tweets)
end
How do I set the parameters from the data returned by the function in the GET route, and pass them to the POST route so I can save to the DB?
Your code has two completely separate endpoints, which are called in separate API requests. You could make it a single POST request, i.e.:
As an alternative, for persisting data between subsequent requests, you would typically use sessions:
A redirect is not possible from GET to POST, because browsers will keep the request method the same after a redirect. You would have to make your first route a POST too.