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 (except when there is an error) , 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.plugin(:retries)

requests = [
  session.build_request("GET", ""),
  session.build_request("POST", "", { body: "bla" })

# IMPORTANT! pass the requests to the session which was used to build them!
responses = session.request(*requests)

:origin (since v0.14)

If you’re only going to query a single domain (i.e. if you are building an API SDK), you can set it using the :origin option, and then send requests using the relative paths only):

api_client = HTTPX.with(origin: "")

:base_path (since v0.20)

You can also set a base path to be prepended to all relative URLs (quite useful for adding API version):

api_client_v1 = HTTPX.with(origin: "", base_path: "/v1")


You can also pass a URI object instead of the “string” uri:

uri = URI("")


Internationalized domain name are also supported:


Next: Pass Parameters