Documentation Index Fetch the complete documentation index at: https://firecrawl-mog-search-exclude-include-domains.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Ajoutez votre clé API à .env :
FIRECRAWL_API_KEY = fc-YOUR-API-KEY
Ajoutez l’entrée de configuration dans config/services.php :
'firecrawl' => [
'api_key' => env ( 'FIRECRAWL_API_KEY' ),
'base_url' => env ( 'FIRECRAWL_API_URL' , 'https://api.firecrawl.dev/v2' ),
],
Créer une classe de service
Créez app/Services/FirecrawlService.php:
<? php
namespace App\Services ;
use Illuminate\Support\Facades\ Http ;
class FirecrawlService
{
private string $apiKey ;
private string $baseUrl ;
public function __construct ()
{
$this -> apiKey = config ( 'services.firecrawl.api_key' );
$this -> baseUrl = config ( 'services.firecrawl.base_url' );
}
public function search ( string $query , int $limit = 5 ) : array
{
$response = Http :: withToken ( $this -> apiKey )
-> post ( "{ $this -> baseUrl }/search" , [
'query' => $query ,
'limit' => $limit ,
]);
return $response -> json ();
}
public function scrape ( string $url , array $options = []) : array
{
$response = Http :: withToken ( $this -> apiKey )
-> post ( "{ $this -> baseUrl }/scrape" , array_merge ([ 'url' => $url ], $options ));
return $response -> json ();
}
public function interact ( string $url , string $prompt , ? string $followUp = null ) : array
{
// 1. Scraper pour ouvrir une session de navigateur
$scrapeResult = $this -> scrape ( $url , [ 'formats' => [ 'markdown' ]]);
$scrapeId = $scrapeResult [ 'data' ][ 'metadata' ][ 'scrapeId' ];
// 2. Envoyer le premier prompt
Http :: withToken ( $this -> apiKey )
-> post ( "{ $this -> baseUrl }/scrape/{ $scrapeId }/interact" , [
'prompt' => $prompt ,
]);
// 3. Envoyer le prompt de suivi
$result = null ;
if ( $followUp ) {
$result = Http :: withToken ( $this -> apiKey )
-> post ( "{ $this -> baseUrl }/scrape/{ $scrapeId }/interact" , [
'prompt' => $followUp ,
]) -> json ();
}
// 4. Fermer la session
Http :: withToken ( $this -> apiKey )
-> delete ( "{ $this -> baseUrl }/scrape/{ $scrapeId }/interact" );
return $result ?? $scrapeResult ;
}
}
Créez app/Http/Controllers/FirecrawlController.php :
<? php
namespace App\Http\Controllers ;
use App\Services\ FirecrawlService ;
use Illuminate\Http\ Request ;
class FirecrawlController extends Controller
{
public function __construct ( private FirecrawlService $firecrawl ) {}
public function search ( Request $request )
{
$validated = $request -> validate ([ 'query' => 'required|string' ]);
return response () -> json (
$this -> firecrawl -> search ( $validated [ 'query' ], $request -> input ( 'limit' , 5 ))
);
}
public function scrape ( Request $request )
{
$validated = $request -> validate ([ 'url' => 'required|url' ]);
return response () -> json ( $this -> firecrawl -> scrape ( $validated [ 'url' ]));
}
public function interact ( Request $request )
{
$validated = $request -> validate ([
'url' => 'required|url' ,
'prompt' => 'required|string' ,
]);
return response () -> json (
$this -> firecrawl -> interact (
$validated [ 'url' ],
$validated [ 'prompt' ],
$request -> input ( 'followUp' )
)
);
}
}
Dans routes/api.php:
use App\Http\Controllers\ FirecrawlController ;
Route :: post ( '/search' , [ FirecrawlController :: class , 'search' ]);
Route :: post ( '/scrape' , [ FirecrawlController :: class , 'scrape' ]);
Route :: post ( '/interact' , [ FirecrawlController :: class , 'interact' ]);
php artisan serve
# Rechercher sur le web
curl -X POST http://localhost:8000/api/search \
-H "Content-Type: application/json" \
-d '{"query": "firecrawl web scraping"}'
# Scraper une page
curl -X POST http://localhost:8000/api/scrape \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com"}'
# Interagir avec une page
curl -X POST http://localhost:8000/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"}'
Docs Search Effectuez une recherche sur le web et obtenez le contenu intégral de la page
Docs Scrape Toutes les options de scrape, y compris les formats, les actions et les proxys
Docs Interact Cliquez, remplissez des formulaires et extrayez du contenu dynamique
Référence API Documentation complète de l’API REST