class FirecrawlController < ApplicationController skip_before_action :verify_authenticity_token def search service = FirecrawlService.new result = service.search(params.require(:query), limit: params.fetch(:limit, 5).to_i) render json: result end def scrape service = FirecrawlService.new result = service.scrape(params.require(:url)) render json: result end def interact service = FirecrawlService.new result = service.interact( params.require(:url), params.require(:prompt), follow_up: params[:followUp] ) render json: result endend
Rails.application.routes.draw do post "api/search", to: "firecrawl#search" post "api/scrape", to: "firecrawl#scrape" post "api/interact", to: "firecrawl#interact"end
rails server# Search the webcurl -X POST http://localhost:3000/api/search \ -H "Content-Type: application/json" \ -d '{"query": "firecrawl web scraping"}'# Scrape a pagecurl -X POST http://localhost:3000/api/scrape \ -H "Content-Type: application/json" \ -d '{"url": "https://example.com"}'# Interact with a pagecurl -X POST http://localhost:3000/api/interact \ -H "Content-Type: application/json" \ -d '{"url": "https://www.amazon.com", "prompt": "Search for iPhone 16 Pro Max", "followUp": "Click on the first result and tell me the price"}'