gitmyhub

httparty

Ruby ★ 5.9k updated 4mo ago

:tada: Makes http fun again!

HTTParty is a Ruby library that makes it easy to call web APIs with a single line of code. It automatically parses JSON and XML responses into Ruby data so you can use them right away without writing any parsing code.

Rubysetup: easycomplexity 2/5

HTTParty is a Ruby library that makes it straightforward to send HTTP requests from your code and work with the responses. HTTP requests are what your program sends when it needs to talk to a web service or API: fetching data from a URL, submitting a form, or calling a third-party service. Ruby has built-in tools for this, but they can be verbose. HTTParty wraps them in a simpler interface so you can get, post, put, or delete with a single line of code.

The library works in two ways. You can call methods directly on the HTTParty module itself for quick one-off requests, passing a URL and getting back a response object that gives you the status code, headers, and body. You can also mix it into your own Ruby class, set a base URL once, and then define methods for specific endpoints. This second approach keeps API-related code organized in one place and makes it easier to reuse options like authentication credentials or default query parameters across multiple requests.

The gem automatically parses response bodies based on the content type. If the server returns JSON or XML, HTTParty converts it to a Ruby data structure so you can access fields directly without writing parsing code yourself.

A command-line tool is included alongside the library. You can run httparty from the terminal with a URL and it prints the response in a readable format, which is useful for quickly checking what an API returns without writing any code.

Installation is through RubyGems with gem install httparty, and the library requires Ruby 2.7 or newer.

Where it fits