jigarakatidus / laravel-http-to-curl
Extended Http to dump and die with Curl command
Installs: 27 522
Dependents: 0
Suggesters: 0
Security: 0
Stars: 29
Watchers: 3
Forks: 3
Open Issues: 0
Requires
- php: ^8.0
- illuminate/support: ^8.71|^9.0|^10.0|^11.0|^12.0
- jigarakatidus/command-line-generator: ^1.0.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.12
- guzzlehttp/psr7: ^2.0
- illuminate/http: ^8.71 || ^9.0 || ^10.0 || ^11.0 || ^12.0
- mockery/mockery: ^1.4.2
- orchestra/testbench: ^9.0 || ^10.0 || ^11.0
- phpunit/phpunit: ^10.0|^11.0|^12.0
README
This package has two use-cases:
- Simple dump and die with curl command for local development for troubleshooting the http request.
- Enable logging curl command for each request in the logs.
Installation
You can pull in the package via composer:
composer require jigarakatidus/laravel-http-to-curl
The package will automatically register itself
Usage
Basic GET Request
Http::ddWithCurl() ->get('https://example.com/api/resource');
Outputs
curl -H 'User-Agent: GuzzleHttp/7' -X 'GET' 'https://example.com/api/resource'
GET Request with Query Parameters
Http::ddWithCurl() ->get('https://example.com/api/resource', [ 'param1' => 'value1', 'param2' => 'value2', ]);
Outputs
curl -H 'User-Agent: GuzzleHttp/7' -X 'GET' 'https://example.com/api/resource?param1=value1¶m2=value2'
POST Request with JSON Payload
Http::ddWithCurl() ->acceptJson() ->post('https://example.com/api/resource', [ 'key1' => 'value1', 'key2' => 'value2', ]);
Outputs
curl -H 'User-Agent: GuzzleHttp/7' -H 'Accept: application/json' -H 'Content-Type: application/json' -X 'POST' 'https://example.com/api/resource' -d '{"key1":"value1","key2":"value2"}'
Automatic Request Logging
To enable the automatic logging of curl command for each request, configure these options directly through environment variables:
HTTP_TO_CURL_LOGGING
: Enable/disable logging (defaults to false)HTTP_TO_CURL_LOG_LEVEL
: Set log level (defaults to "debug")HTTP_TO_CURL_LOG_CHANNEL
: Select log channel (defaults to "stack")
Optionally, you can publish the configuration file using the following command:
php artisan vendor:publish --tag=http-to-curl-config
This will create a config/http-to-curl.php
file where you can customize the logging behavior.
Logging Example
When you enable logging by setting HTTP_TO_CURL_LOGGING=true
in your environment, all HTTP requests will be automatically logged. For example, if your application makes this request:
Http::post('https://api.example.com/users', [ 'name' => 'John Doe', 'email' => 'john@example.com' ]);
This cURL command will be automatically logged to your configured log channel:
[2025-05-13 23:53:46] local.DEBUG: curl -H 'User-Agent: GuzzleHttp/7' -H 'Content-Type: application/json' -X 'POST' 'https://api.example.com/users' -d '{"name":"John Doe","email":"john@example.com"}'
This is useful for debugging API calls in both development and production environments.
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
$ composer test
Contributing
Pull Requests are welcome.
Security
If you've found a bug regarding security please mail jigar.tidus@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.