vivek
vivek

Reputation: 2867

Communicating with remote apis including rails

I am fairly new to rails. In my project I have to do a number of api calls(POST) to many servers. Each call requires a number of arguments which needs to be send via POST request. The response will be simple with just json data. Can anyone suggest be some better way to do this or someone has an experience with this kind of stuff. Most of these operation will be just single round strip.

I have read Active Resource and net::HTTP and I am confused which one to use. Since Active Resource is just for RESTful api so I don't know before hand if the server I will be communicating to will be providing the same.

Thanks in advance!

Upvotes: 1

Views: 1233

Answers (3)

Anezio Campos
Anezio Campos

Reputation: 1555

You must check if the API is working with REST or SOAP.

If it is a REST you could use rest-client gem

If it uses SOAP you can use savon gem

Upvotes: 1

Simone Carletti
Simone Carletti

Reputation: 176352

ActiveResource is a kind of framework for interacting with RESTful APIs. Rails is going to remove AR from the core dependencies in Rails 4.0, thus I don't suggest to use it unless you need to work with another Rails app.

In your case, you need an HTTP library. The standard Ruby HTTP library is Net::HTTP. There are several other clients, mostly based on Net::HTTP. One of these is rest-client.

You can use Net::HTTP directly or use another client, such as rest-client, faraday, httparty, etc. Net::HTTP doesn't expose a very nice API, that's the reason why exist several alternative clients and wrappers.

FYI, ActiveResource is also based on Net::HTTP.

Upvotes: 0

fotanus
fotanus

Reputation: 20106

net::HTTP can really make your code messy in a small amount of time. You should pick any REST gem that is out there, for example, rest client.

Upvotes: 0

Related Questions