承接 wbsartori/request-manager 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

wbsartori/request-manager

最新稳定版本:v0.0.4

Composer 安装命令:

composer require wbsartori/request-manager

包简介

Request Manager is a PHP HTTP client library containing the abstraction of the Guzzle and PhpCurlClass libraries

README 文档

README

Requirements

Request Management Package requires PHP version 7.3.0 or greater.

Installation

To use the package it is necessary to install it via composer:
composer require wbsartori/request-manager

Basic Example of use GuzzleRequest

You can call the Runner class and in the setClient method pass the client you want to use, currently our package supports GuzzleRequet and PhpCurlClass with some abstractions.

GET Method with basic authentication

    use RequestManager\RequestRunner;
    use RequestManager\Http\GuzzleRequestAdapter;
    
    try {
        $url = sprintf('%s%s',
          '/',$router
        );

        $response = (new RequestRunner())
            ->setClient(new GuzzleRequestAdapter())
            ->basicAuth($username, $password)
            ->setHeader($headers)
            ->setUri($uri)
            ->get($url);
    
            echo json_encode($response);

    } catch (Exception $e) {
        echo json_encode([
            'code: ' => $e->getCode(),
            'message: ' => $e->getMessage()
        ]);
    }

POST Method with basic authentication

    
    use RequestManager\RequestRunner;
    use RequestManager\Requests\GuzzleRequest;
    
    try {
        $data = [
            [
                'description' => 'description',
                'acronym' => 'acronym'
            ]
         ];
         
        $url = sprintf('%s%s',
            '/', $router
        );
        
        $response = (new RequestRunner())
            ->setClient(new GuzzleRequest())
            ->basicAuth($username, $password)
            ->setHeader(['header' => ''])
            ->setUri($uri)
            ->setData(['multipart' => $data])
            ->post($url);
    
        echo json_encode($response);
    
    } catch (Exception $e) {
        echo json_encode([
            'code: ' => $e->getCode(),
            'message: ' => str_replace('\\', '', $e->getMessage())
        ]);
    }
    

UPDATE Method with basic authentication

        
    use RequestManager\RequestRunner;
    use RequestManager\Requests\GuzzleRequest;
    
    try {
        $data = [
            'description' => 'New description',
            'acronym' => 'NA'
        ];
        
        $url = sprintf('%s%s%s%s',
        '/',
            $router,
            DIRECTORY_SEPARATOR,
            30
        );
        
        $response = (new RequestRunner())
            ->setClient(new GuzzleRequest())
            ->basicAuth($username, $password)
            ->setHeader(['header' => ''])
            ->setUri($uri)
            ->setData(['json' => $data])
            ->put($url);
    
        echo json_encode($response);
    
    } catch (Exception $e) {
        echo json_encode([
            'code: ' => $e->getCode(),
            'message: ' => str_replace('\\', '', $e->getMessage())
        ]);
    }
    

DELETE Method with basic authentication

        
    use RequestManager\RequestRunner;
    use RequestManager\Requests\GuzzleRequest;
    
    try {
        $url = sprintf('%s%s%s%s',
        '/',
            $router,
            DIRECTORY_SEPARATOR,
            30
        );
    
        $response = (new RequestRunner())
            ->setClient(new GuzzleRequest())
            ->basicAuth($username, $password)
            ->setHeader(['header' => ''])
            ->setUri($uri)
            ->delete($url);
    
        echo json_encode($response);

    } catch (Exception $e) {
        echo json_encode([
            'code: ' => $e->getCode(),
            'message: ' => $e->getMessage()
        ]);
    }

Methods

    setClient((new Client));         #Set the Client you want to use, if you don't use this method, Guzzle will be set as default.
    basicAuth($username, $password); #Basic authentication, if not used, the default noAuth will be used.
    bearerTokenAuth($token);         #Bearer token authentication, if not used, the default noAuth will be used.
    setHeader($headers)              #Receives an array of headers from the request if necessary.
    setUri($uri)                     #Get the api host with the slash at the end.
    setData($uri)                    #Receives an array of data if the method needs to pass some value.
    get($url)                        #Receives the route for which you want to fetch data.
    post($url)                       #Get the route for which you want to create data.
    put($url)                        #Get the route for which you want to update data.
    delete($url)                     #Get the route for which you want to delete data.

You can check the documentation for examples of using Guzzle and PHPCurlClass.

Documentantion

Link to documentation and examples.

Contributing

Link to contributing.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: proprietary
  • 更新时间: 2023-04-14