Skip to main content

Ruby · Code recipe

Get a page's metadata and Open Graph tags in Ruby

Read the title, description and share image of any page, in Ruby 3.1+ with Net::HTTP from the standard library. Every program on this page runs as it stands — each one was run against a stub of the API before it was published.

By · Last updated: September 2026

TL;DR

To read a page's title, description, Open Graph image and other metadata in Ruby, POST its URL to https://urlpipe.dev/meta with sync set to true and parse the JSON with JSON.parse. It answers with the same keys for every page — null where the page declares nothing — for 1 credit, the same as a page fetch.

Free plan, no credit card. 1,000 credits a month.

One POST to /meta renders the page and returns what it says about itself, with the same keys on every page: title, description, site name, language, authors, publication and update dates, share image, favicon, feeds and more. URLs come back absolute, resolved against the page.

It reads every place a page declares its metadata — Open Graph, Twitter cards, JSON-LD, plain tags — and settles conflicts by a fixed order: og:title, then twitter:title, then <title>, then the <h1>. A field the page never declares is null, never a guess, and it costs 1 credit, the same as a page fetch. In Ruby, JSON.parse gives you the fields; the Open Graph guide covers which tags each platform reads.

Setup

Before you start

Nothing to install: net/http and json are part of Ruby. Put your API key in the environment so it never lands in the file.

Terminal
ruby --version   # 3.1 or later
export URLPIPE_API_KEY="your_api_key"

The request

Print the title, description and main image

sync: true keeps the request open until the result is ready. use_ssl: has to be asked for — Net::HTTP does not infer it from the scheme — and abort prints to stderr and exits 1. Any field can be nil, hence the || "none".

page_metadata.rb
require "json"
require "net/http"

uri = URI("https://urlpipe.dev/meta")
# read_timeout: a sync call can take up to 60 s, Net::HTTP's default.
res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https", read_timeout: 90) do |http|
  http.post(uri.path, { url: "https://example.com", sync: true }.to_json,
            "Authorization" => "Bearer #{ENV.fetch("URLPIPE_API_KEY")}",
            "Content-Type" => "application/json")
end
abort "URLpipe answered #{res.code}: #{res.body}" unless res.is_a?(Net::HTTPOK)

meta = JSON.parse(res.body)
puts "Title: #{meta["title"] || "none"}"
puts "Description: #{meta["description"] || "none"}"
puts "Image: #{meta.dig("image", "url") || "none"}"

Run it: ruby page_metadata.rb

Given the example response on the docs page, it prints:

Output
Title: Example Domain
Description: Illustrative examples in documents.
Image: https://example.com/cover.jpg

Async

The async variant: a token, a webhook and a poll

Leave out sync and the answer is a token, straight away. Net::HTTP reports the status as a string, so the poll compares res.code with "202", not the number.

page_metadata_async.rb
require "json"
require "net/http"

API = URI("https://urlpipe.dev")

def send_request(request)
  request["Authorization"] = "Bearer #{ENV.fetch("URLPIPE_API_KEY")}"
  Net::HTTP.start(API.host, API.port, use_ssl: API.scheme == "https") { |http| http.request(request) }
end

# No sync: the request is accepted at once and the work carries on without you.
post = Net::HTTP::Post.new(URI.join(API, "/meta"), "Content-Type" => "application/json")
post.body = {
  url: "https://example.com",
  report_to: "https://your-app.com/webhooks/urlpipe",
  labels: { customer: "acme" }
}.to_json
res = send_request(post)
abort "URLpipe answered #{res.code}: #{res.body}" unless res.is_a?(Net::HTTPOK)
token = JSON.parse(res.body).fetch("token")
puts "Accepted #{token}"

# The result is POSTed to report_to when it is ready. Polling by token is the
# other way to collect it: no endpoint needed, and a backup for the webhook.
60.times do
  res = send_request(Net::HTTP::Get.new(URI.join(API, "/result/#{token}")))
  break unless res.code == "202" # 202 means still processing

  sleep 2
end

case res.code
when "200" then nil
when "202" then abort "Still processing after two minutes; try the token again later."
when "422" then abort "The analysis failed: #{JSON.parse(res.body)["error"]}"
when "410" then abort "The result is past the 30-day window; send the request again."
else abort "URLpipe answered #{res.code}: #{res.body}"
end

meta = JSON.parse(res.body)
puts "Title: #{meta["title"] || "none"}"
puts "Description: #{meta["description"] || "none"}"
puts "Image: #{meta.dig("image", "url") || "none"}"

Run it: ruby page_metadata_async.rb

Errors

Handle errors and retries

Pattern matching on [status, code] keeps the retry rules in one place. A 401 answers in plain text, so it is checked before JSON.parse, and a body that still is not JSON becomes an empty hash.

page_metadata_errors.rb
require "json"
require "net/http"

class URLpipeError < StandardError; end

# POST a sync request and return the response, or raise URLpipeError.
def urlpipe(path, payload, attempts: 5)
  uri = URI("https://urlpipe.dev#{path}")
  attempts.times do |attempt|
    res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https", read_timeout: 90) do |http|
      http.post(uri.path, payload.merge(sync: true).to_json,
                "Authorization" => "Bearer #{ENV.fetch("URLPIPE_API_KEY")}",
                "Content-Type" => "application/json")
    end
    return res if res.code == "200"
    raise URLpipeError, "401: the API key is missing or wrong. Check URLPIPE_API_KEY." if res.code == "401"

    body = begin
      JSON.parse(res.body)
    rescue JSON::ParserError
      {}
    end
    code = body["error"].to_s
    detail = body["message"] ? "#{code}: #{body["message"]}" : code

    case [ res.code, code ]
    in [ "429", "rate_limited" ]
      # Sending too fast: Retry-After says how long the window has left.
      sleep Integer(res["Retry-After"] || 1)
    in [ "429", "concurrency_limit" ]
      # Every parallel slot on your plan is busy with your own requests.
      sleep 2**attempt
    in [ "504", _ ]
      # Still running on our side; the token collects it from GET /result/:token.
      raise URLpipeError, "504 processing_timeout: collect it later with token #{body["token"]}"
    else
      # 403 email_unverified, 422 (a bad parameter, or a page that would not load),
      # 429 quota_exceeded: sending the same request again gets the same answer.
      raise URLpipeError, "#{res.code}: #{detail}"
    end
  end
  raise URLpipeError, "429: still refused after #{attempts} attempts"
end

begin
  res = urlpipe("/meta", { url: "https://example.com" })
rescue URLpipeError => e
  abort "URLpipe: #{e.message}"
end

meta = JSON.parse(res.body)
puts "Title: #{meta["title"] || "none"}"
puts "Description: #{meta["description"] || "none"}"
puts "Image: #{meta.dig("image", "url") || "none"}"

Run it: ruby page_metadata_errors.rb

Details

What to know about /meta

  • Any field can be null when the page does not have it — code for that, as the program does.
  • There is no canonical field; the nine fields are the whole response.
  • Image and favicon URLs that are data URIs come back as null rather than as a blob.
  • Pages over 10 MB of HTML are refused before the model sees them.

Client library

Or use the official Ruby client

The same call in one line, with retries that never bill twice, typed errors, long analyses waited out for you and webhook verification. Ruby 3.1+, no dependencies.

urlpipe
# gem install urlpipe

require "urlpipe"

client = Urlpipe::Client.new # reads ENV["URLPIPE_API_KEY"]

page = client.markdown("https://example.com")
puts page.data

Other languages

Get a page's metadata and Open Graph tags in another language

More Ruby: every Ruby recipe

FAQ

Frequently asked questions

Which fields does /meta return?
title, description, site_name, type, language, locale, authors, published_at, modified_at, image, video, favicon_url, icons, logo_url, feeds, keywords, canonical_url, robots, alternates and more, plus the raw open_graph and twitter tags. Every key is always there; a value the page doesn't declare is null or an empty list.
How much does it cost?
1 credit per page, the same as /html: the page's own declarations are read without a model. A result reused within max_age is free.
Do I need an SDK to call URLpipe from Ruby?
No gem is needed: Net::HTTP and json are in the standard library, and the API is one POST per job. If you'd rather use one, the official client installs with gem install urlpipe and adds retries that never bill twice, typed errors and webhook verification.

Get a key and run it.

Free plan, no card. Paste your key into URLPIPE_API_KEY and every program on this page runs as it is.