httpartyvsnestful
HTTParty is a Ruby library that makes it easy to work with HTTP requests and responses. It is built on top of the Ruby standard library's Net::HTTP and provides a simple, easy-to-use interface for making requests and handling responses.
One of the main features of HTTParty is its ability to automatically parse response bodies as JSON, XML, or other formats. This allows developers to easily access the data returned by an API without having to manually parse the response.
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 'httparty'
# get request:
response = HTTParty.get('http://httpbin.org/get')
puts response.body
puts response.code
puts response.message
puts response.headers.inspect
# post request
response = HTTParty.post('http://httpbin.org/post',
: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