定制 directions/http-wrapper 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

directions/http-wrapper

最新稳定版本:0.1.0

Composer 安装命令:

composer require directions/http-wrapper

包简介

Wrapper around HTTP Facade in Laravel

README 文档

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();

统计信息

  • 总下载量: 13
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2024-11-08