Make Requests

Making a request is very simple:

require "httpx"
puts HTTPX.get("").to_s #=> "<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">..."

Performing a request will return an HTTPX::Response, which will allow you to perform a few more operations beyond getting the payload. For instance, this is how you’d check it’s status and headers:

require "httpx"
response = HTTPX.get("")
puts response.status #=> 302
puts response.headers["location"] #=> ""

Many other request type methods are available:

require "httpx""", body: "blabla")
HTTPX.patch("", body: "blabla")

Multiple Requests

Sending multiple requests is as simple as passing them. An array of responses will be returned:

require "httpx"
responses = HTTPX.get("", "", "", "")

puts #=> "<HTML>..."

# since v0.9, You can also pass different requests like this:

requests = [
  [:get, ""],
  [:post, "", body: "bla"]

responses = HTTPX.request(*requests)

# Or, when a session object is available
session = HTTPX::Session
# or session = HTTPX.plugin(:compression)

requests = [
  session.build_request(:get, ""),
  session.build_request(:post,  "", body: "bla")

responses = HTTPX.request(*requests)


Headers can either be part of the client’s configuration, or passed to the specific requests.

require "httpx"

http = HTTPX.headers("accept" => "text/html")
http.get("") # sends request with "accept: text/html"
http.get("", headers: { "accept-language" => "swahili" }) # sends the "accept-language: swahili" along with the previous "accept" header

Next: Pass Parameters