exconvsnestful
Excon is a Ruby library for making HTTP requests. It is designed to be fast and efficient, and is often used as a building block for other Ruby libraries and frameworks.
One of the main features of Excon is its support for persistent connections, which allows it to reuse the same connection for multiple requests, reducing the overhead of establishing a new connection for each request.
Excon also supports streaming requests and responses, which allows you to read or write data to the server incrementally, without having to load the entire response into memory at once.
Nestful is a Ruby library for making HTTP requests. It is designed to provide a simple, easy-to-use interface for making requests and handling responses. Nestful is often used for making requests to RESTful APIs.
One of the main features of Nestful is its ability to automatically parse JSON and XML responses and return them as Ruby objects. This allows developers to easily access the data returned by an API without having to manually parse the response.
Netful is aimed at interacting with rest APIs and provides a convenient interface (see example below)
Example Use
require 'excon'
# GET requests
response = Excon.get('https://jsonplaceholder.typicode.com/posts/1')
puts response.body
puts response.status
puts response.headers
# POST requests
response = Excon.post('https://jsonplaceholder.typicode.com/posts',
:body => { :title => 'foo', :body => 'bar', :userId => 1 }.to_json,
:headers => { 'Content-Type' => 'application/json' } )
puts response.body
require 'nestful'
# GET request
response = Nestful.get('http://httpbin.org/get')
puts response.body
puts response.code
puts response.headers
# POST request
response = Nestful.post(
'http://httpbin.org/post',
:format => :json, :payload => { :title => 'foo', :body => 'bar', :userId => 1 }
)
puts response.body
# establish interface to a specific API
class Charge < Nestful::Resource
endpoint 'https://api.stripe.com/v1/charges'
options :auth_type => :bearer, :password => 'sk_bar'
def self.all
self.new(get)
end
def self.find(id)
self.new(get(id))
end
def refund
post(:refund)
end
end
Charge.all #=> []
Charge.find('ch_bar').amount