In today's world, building a web application without relying on third-party APIs is almost impossible, which is why it is essential to monitor the outgoing HTTP requests from our application.
Tracking and logging external requests and responses improves application observability, helps detect slow APIs, and makes it easier to find out why certain integrations fail.
Having a timeline of requests and responses helps us review communication with third parties and extract useful information that may have been overlooked during API implementation.
Laravel Spy is a powerful package for Laravel designed to track and log the outgoing HTTP requests made by your application. It is very useful for debugging, monitoring, and auditing external calls, showing details such as URL, methods, headers, and responses.
To install it, run the command composer require farayaz/laravel-spy and then publish the configuration with php artisan vendor:publish --provider=Farayaz\LaravelSpy\LaravelSpyServiceProvider; then run the migrations with php artisan migrate to prepare the database where the logs will be stored.
The configuration file config/spy.php includes key options such as table_name, which defaults to http_logs, enabled to activate or deactivate logging, db_connection to use a separate database connection, exclude_urls to list URLs that should not be logged, and obfuscates to hide sensitive data such as passwords or secrets in the logs.
Laravel Spy allows you to use an independent database connection through the db_connection option in the configuration to avoid overloading the main connection in high-traffic applications. Additionally, it is important to configure obfuscates to protect sensitive data in the logs.
To verify that it works, you can add a test route, for example Route::get(/spy, function() { Http::get(https://github.com/farayaz/laravel-spy/); }); and then check the http_logs table in the database to see the logged parameters.
In each logged request, you will be able to see the full URL, the HTTP method such as GET or POST, the request headers, the request body, the response headers, the response body, and the HTTP status code.
Laravel Spy is open source under the MIT license, and contributions to the project are welcome.
At Q2BSTUDIO, we are a software development company specialized in custom applications and custom software. We offer comprehensive services that include artificial intelligence implementations and AI solutions for businesses, as well as custom AI agent developments. We are also experts in cybersecurity and optimized cloud deployments with AWS and Azure cloud services. Additionally, we provide business intelligence services and Power BI consulting to turn data into decisions and improve business performance.
If you need to integrate advanced external request logging, audit API integrations, or deploy secure and scalable solutions on AWS or Azure, at Q2BSTUDIO we help you implement Laravel Spy and other tools to ensure traceability, security, and advanced analysis with artificial intelligence and Power BI.
Keywords: custom applications, custom software, artificial intelligence, cybersecurity, AWS and Azure cloud services, business intelligence services, AI for businesses, AI agents, Power BI.



