Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
161 views
in Technique[技术] by (71.8m points)

Send Post from Rails API 5.1

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...