farayaz / laravel-spy
A Laravel package to track outgoing HTTP requests.
Requires
- php: ^8.1
- laravel/framework: ^10.0|^11.0|^12.0
Requires (Dev)
- laravel/pint: ^1.0
- phpunit/phpunit: ^9.0
README
Laravel Spy is a lightweight Laravel package designed to track and log outgoing HTTP requests made by your Laravel application.
This package is useful for debugging, monitoring, and auditing external API calls or HTTP requests, providing developers with a zero config, simple way to inspect request details such as URLs, methods, headers, and responses.
Features
- Tracks all outgoing HTTP requests made via Laravel's HTTP client.
- Logs request details, including URL, method, headers, payload, and response.
- Configurable logging options to customize and obfuscate sensitive data.
Requirements
- PHP: ^8.1
- Laravel: ^10.0 | ^11.0 | ^12.0
- Development Dependencies (optional):
laravel/pint
: ^1.0 (for code style linting)phpunit/phpunit
: ^9.0 (for running tests)
Installation
You can install the package via Composer:
composer require farayaz/laravel-spy
The package uses Laravel's auto-discovery feature. After installation, the package is ready to use with its default configuration.
By Default Laravel-Spy
logs all HTTP requests and API calls. You can customize it to exclude specific URLs or obfuscate sensitive data.
Configuration
To customize the behavior of Laravel Spy, you can publish the configuration file:
php artisan vendor:publish --provider="Farayaz\LaravelSpy\LaravelSpyServiceProvider"
php artisan migrate
This will create a config/laravel-spy.php
file where you can configure the following options:
'table_name' => 'http_logs',
'enabled' => env('SPY_ENABLED', true),
'db_connection' => env('SPY_DB_CONNECTION'),
'exclude_urls' => explode(',', env('SPY_EXCLUDE_URLS', '')),
'obfuscates' => explode(',', env('SPY_OBFUSCATES', 'password')),
Usage
Once installed and configured, Laravel Spy automatically tracks all outgoing HTTP requests made using Laravel's Http facade or HTTP client. The package logs the following details for each request:
- The full URL of the request
- The HTTP method (e.g., GET, POST, PUT)
- Request Headers
- Request Body
- Response Header
- Response Body
- Response HTTP Status code
Example:
Once you’ve installed Laravel-Spy
via Composer and published the configuration, open your web.php
file and add the following line to start logging results into the http_logs
table in your database:
Route::get("/spy", function () { Http::get('https://github.com/farayaz/laravel-spy/'); });
Now head to the http_logs
table to view the logged parameters.
Contributing
Contributions are welcome! To contribute to Laravel Spy:
- Fork the repository on GitHub.
- Clone your fork and create a new branch (git checkout -b feat-your-feature).
- Run code style checks with Laravel Pint (vendor/bin/pint).
- Commit your changes and push to your fork.
- Create a pull request with a clear description of your changes.
Issues
If you encounter any issues or have feature requests, please open an issue on the GitHub repository. Provide as much detail as possible, including:
- Laravel version
- PHP version
- Package version
- Steps to reproduce
- Expected vs. actual behavior
- Any relevant error messages or logs
License
Laravel Spy is open-sourced software licensed under the MIT License.
Contact
For questions or support, reach out via the GitHub repository or open an issue.