tyasa81 / requestwrapper
Simple Request Wrapper
Fund package maintenance!
Tony Yasa
Requires
- php: ^8.2
- illuminate/contracts: ^10.0||^11.0
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
README
This is a wrapper for request using Guzzle and Curl. It is mainly used to simplify request code in a request heavy project that deals with cookies and proxy. Facade are made for backward compatiblity on previous project where a lot of static methods are used. Refactoring code into a service class and package are made since it made using Guzzle and Curl much cleaner even for projects that are not cookies or proxy centric.
Installation
You can install the package via composer:
composer require tyasa81/requestwrapper
You can publish the config file with:
php artisan vendor:publish --tag="requestwrapper-config"
Usage
Using Facades:
use tyasa81\RequestWrapper\Facades\RequestWrapper; $response = RequestWrapper::getUrl("https://httpbin.org/ip",true); dd($response);
Available functions:
public static function postUrl($url, $payload, $json=false, &$args=array(), $retry=1, $sleep=1, $timeout=15, $type="POST") public static function getUrl($url, $json=false, &$args=array(), $retry=1, $sleep=1, $timeout=15) public static function postMultiPartUrl($url, $multipart, $json=false, &$args=array(), $retry=1, $sleep=1, $timeout=15, $type="POST") public static function getAsync($url_datas, $json=false, $args=array(), $timeout=15) public static function UrlwithProxy($url, $json=false, &$args=array(), $proxy_type="FAST", $type="GET", $retry=5, $sleep=0, $timeout=15) public static function requestCurlProxyRetry($url, $payload, $json=false, &$args=array(), $type="GET", $proxy_type="GLOBAL", $proxy_index=null, $timeout=20,$retry = 4) public static function requestCurlProxy($url, $payload, $json=false, &$args=array(), $type="GET", $proxy_type="GLOBAL", $proxy_index=null, $timeout=20) public static function requestCurl($url, $payload, $json=false, &$args=array(), $type="GET", $proxy_type=null, $proxy_index=null, $timeout=15,$retry=0,$sleep=0) // Helpers Functions public static function formatCookieJarToString(CookieJar $cookieJar) public static function getCookieValue(CookieJar $cookieJar, string $cookieName) public static function convertGuzzleCookieJarToSession(CookieJar $cookieJar) public static function getCookieJarFromSession(string $session)
Using Service Class:
$curlwrapper = new CurlWrapper(cookieJar: $cookieJar); $response = $curlwrapper->request(url: "https://httpbin.org/ip", json: true);
OR
$guzzlewrapper = new GuzzleWrapper(cookieJar: $cookieJar); $response = $guzzlewrapper->request(url: "https://httpbin.org/ip", json: true);
Interface:
request(string $url, $payload=null, bool $json=false, array $headers=array(), string $type="POST", string $proxy_type=null, int $proxy_index=null, int $retry=1, int $sleep=1, int $timeout=15, bool $allow_redirects=null, bool $decode_content=null)
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.