PHPackages                             vildanbina/hookshot - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. vildanbina/hookshot

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

vildanbina/hookshot
===================

A Laravel package for transparently capturing and storing HTTP requests with configurable storage drivers

1.0.0(9mo ago)271.7kMITPHPPHP ^8.2CI passing

Since Jul 18Pushed 9mo agoCompare

[ Source](https://github.com/vildanbina/hookshot)[ Packagist](https://packagist.org/packages/vildanbina/hookshot)[ GitHub Sponsors](https://github.com/vildanbina)[ RSS](/packages/vildanbina-hookshot/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (10)Versions (2)Used By (0)

HookShot
========

[](#hookshot)

[![Tests](https://github.com/vildanbina/hookshot/actions/workflows/tests.yml/badge.svg)](https://github.com/vildanbina/hookshot/actions/workflows/tests.yml)[![Latest Stable Version](https://camo.githubusercontent.com/1ab4755bea5aadf4bb78f240bf0ea974add4e6762863e8c70dae3a844727b0ce/68747470733a2f2f706f7365722e707567782e6f72672f76696c64616e62696e612f686f6f6b73686f742f762f737461626c65)](https://packagist.org/packages/vildanbina/hookshot)[![Total Downloads](https://camo.githubusercontent.com/4c6f974b076c09dbded615653f33b1e5a5f383f335aaf9123a77e69f083c56db/68747470733a2f2f706f7365722e707567782e6f72672f76696c64616e62696e612f686f6f6b73686f742f646f776e6c6f616473)](https://packagist.org/packages/vildanbina/hookshot)[![License](https://camo.githubusercontent.com/e66bc78dc7d012a6fe58aedb6cfb8a03d836d33dec6f2dbe70ecd0179cb48a12/68747470733a2f2f706f7365722e707567782e6f72672f76696c64616e62696e612f686f6f6b73686f742f6c6963656e7365)](https://packagist.org/packages/vildanbina/hookshot)[![PHP Version Require](https://camo.githubusercontent.com/6d1f1f40217669377370380a414d70b358604de17468434b3687a396fbca2171/68747470733a2f2f706f7365722e707567782e6f72672f76696c64616e62696e612f686f6f6b73686f742f726571756972652f706870)](https://packagist.org/packages/vildanbina/hookshot)

A Laravel package for capturing and tracking HTTP requests with configurable storage drivers and filtering options.

Overview
--------

[](#overview)

HookShot provides middleware-based HTTP request tracking for Laravel applications. It captures request/response data and stores it using database, cache, or file storage drivers with configurable filtering and performance controls.

**How it works:** The middleware captures request data during the request lifecycle and stores the complete request/response information during Laravel's `terminate` phase, ensuring your application's response time is not affected by the logging process.

### Why HookShot?

[](#why-hookshot)

- **🔍 Debug Issues** - Reproduce bugs by seeing exactly what requests caused them
- **📊 Analytics** - Track API usage patterns, popular endpoints, and user behavior
- **🛡️ Security** - Monitor suspicious requests and track authentication attempts
- **📋 Compliance** - Meet audit requirements with comprehensive request logging
- **⚡ Performance** - Identify slow endpoints and optimize request handling
- **🔌 API Monitoring** - Track external API integrations and webhook deliveries

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 11.x, 12.x

Installation
------------

[](#installation)

Install via Composer:

```
composer require vildanbina/hookshot
```

Publish configuration:

```
php artisan vendor:publish --tag=hookshot-config
```

Run migrations for database storage:

```
php artisan migrate
```

Usage
-----

[](#usage)

### Middleware Registration

[](#middleware-registration)

**Manual Registration (Recommended)**

Apply to specific routes:

```
Route::middleware('track-requests')->group(function () {
    Route::get('/api/users', [UserController::class, 'index']);
    Route::post('/api/users', [UserController::class, 'store']);
});
```

**Global Registration (Laravel 11+)**

Add to `bootstrap/app.php`:

```
->withMiddleware(function (Middleware $middleware) {
    $middleware->append(\VildanBina\HookShot\Middleware\TrackRequestsMiddleware::class);
})
```

### Retrieving Tracked Data

[](#retrieving-tracked-data)

```
use VildanBina\HookShot\Facades\RequestTracker;

// Get all recent requests
$requests = RequestTracker::get(50);

// Find specific request by ID
$request = RequestTracker::find('uuid-here');

// Get requests with database driver (supports advanced queries)
$slowRequests = RequestTracker::query()
    ->where('execution_time', '>', 2.0)
    ->where('response_status', '>=', 400)
    ->get();

// Filter by date range
$todayRequests = RequestTracker::query()
    ->whereDate('timestamp', today())
    ->get();
```

### Event Integration

[](#event-integration)

Listen to request capture events:

```
use VildanBina\HookShot\Events\RequestCaptured;
use Illuminate\Support\Facades\Event;

Event::listen(RequestCaptured::class, function (RequestCaptured $event) {
    $request = $event->request;
    $requestData = $event->requestData;

    // Do something with the request and request data
});
```

Features
--------

[](#features)

**Storage Drivers:**

- Database: Full query support with Eloquent models
- Cache: In-memory storage with configurable TTL
- File: JSON or raw format file logging
- Custom: Implement your own storage driver

**Filtering &amp; Sampling:**

- Path exclusion patterns
- User agent filtering
- Configurable sampling rates
- Content-type based exclusions

**Performance Controls:**

- Request/response payload size limits
- Queue-based processing support
- Automatic data retention cleanup

**Security:**

- Sensitive header filtering
- Authentication data redaction
- Configurable data sanitization

Configuration
-------------

[](#configuration)

All configuration options with their purposes:

```
