Firecrawlrb

A zero-dependency Ruby client for the Firecrawl API. Uses only Ruby standard library (Net::HTTP, URI, JSON).

Installation

Add this line to your application's Gemfile:

gem 'firecrawlrb', path: '../firecrawlrb'

And then execute:

$ bundle install

Usage

Configuration

You can provide your Firecrawl API key via an environment variable:

export FIRECRAWL_API_KEY='fc-your_api_key_here'

Or via a configuration block in a Rails initializer (config/initializers/firecrawlrb.rb):

require 'firecrawlrb'

Firecrawlrb.configure do |config|
  config.api_key = ENV['FIRECRAWL_API_KEY']
end

Or pass it directly when initializing the client:

client = Firecrawlrb::Client.new(api_key: 'fc-your_api_key_here')

LLM JSON Extraction

You can specify a target URL, schema (concise Ruby Hash/Array or raw JSON Schema), and prompt to receive back JSON matching your schema:

Concise Ruby Schema Example

client = Firecrawlrb::Client.new

schema = {
  products: [
    {
      url: :string,
      image_url: :string,
      price: :string,
      name: :string
    }
  ]
}

prompt = "extract the products from the main product list site for https://www.blindster.com"

products = client.extract(
  url: "https://www.blindster.com",
  schema: schema,
  prompt: prompt
)

puts products
# => { "products" => [ { "name" => "...", "price" => "...", "image_url" => "...", "url" => "..." } ] }

Raw JSON Schema Example

schema = {
  type: "object",
  required: [],
  properties: {
    products: {
      type: "array",
      items: {
        type: "object",
        required: [],
        properties: {
          url: { type: "string" },
          image_url: { type: "string" },
          price: { type: "string" },
          name: { type: "string" }
        }
      }
    }
  }
}

products = client.extract(
  url: "https://www.blindster.com",
  schema: schema,
  prompt: prompt
)

License

The gem is available as open source under the terms of the MIT License.