Sending a request through a RailsAPI is an old topic. However, I didn't see more updated information.
I have a case where I need through a Ruby on Rails (5.1) (+ Grape) API, to receive a user's registration in the API and after saving, send through the API a post with this data to a second API.
How could I do this in the best way?
Because has this GEM: https://github.com/fnando/aitch
And there is the old method using:
require 'uri'
require 'net/http'
url = URI.parse('https://url/api')
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = (url.scheme == 'https')
request = Net::HTTP::Post.new(url.path)
request.content_type = 'application/json
response = http.request(request)
In this second case, I really don't know if it would make more sense to put it on the controller or on the model. Anyway, it's an old way of doing it. If anyone has a better way than these two, it would help a lot.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…