directions / http-wrapper
There is no license information available for the latest version (0.1.0) of this package.
Wrapper around HTTP Facade in Laravel
0.1.0
2024-11-08 13:15 UTC
Requires
- php: ^8.1
- laravel/framework: ^9 || ^10 || ^11
This package is auto-updated.
Last update: 2025-06-08 15:32:20 UTC
README
Wrapper around HTTP Facade in Laravel for simple requests
Converts any request into Entity/Class.
Installation & Usage
Requires PHP 8.1+
Require HttpWrapper using Composer:
composer require directions/http-wrapper
How to use?
Simple HTTP request:
<?php
use Directions\HttpWrapper\Request;
use Directions\HttpWrapper\Traits\QueryParams;
use Directions\HttpWrapper\Traits\UserAgent;
class MyRequest extends Request
{
// Add if the request uses Query params
// This will add the @setQueryParams(array $params)
// and then will auto add these params
use QueryParams;
// Add if the request should use custom user-agent value
// setUserAgent(string $user_agent)
use UserAgent;
protected int $timeout = 30;
protected string $base_url;
protected string $path;
protected HttpType $http_type;
protected BodyType $body_type;
protected ResponseType $response_type = ResponseType::None;
}
Make sure to init your values.
Then call:
MyRequest::getInstance()->submit();
Add Payload:
class MyRequest extends Request
{
public function getPayload(): array
{
return [
'param_1' => 1,
'param_2' => 'value 2',
];
}
}
Parse the response:
class MyRequest extends Request
{
public function parse_response(Response $response): mixed
{
if ($response->successful()) {
return $response->object();
}
return null;
}
}
MyRequest::getInstance()->get_response();