定制 juststeveking/http-slim 二次开发

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

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

juststeveking/http-slim

最新稳定版本:v2.1.0

Composer 安装命令:

composer require juststeveking/http-slim

包简介

A slim psr compliant http client to provide better interoperability.

README 文档

README

Latest Version Software License PHP Version run-tests Total Downloads

The purpose of this package is to create an interoperable http client implementation allowing a "bring you own packages" approach to connection to 3rd party services.

The main goal of this package is to adhere to the following PSRs:

Installation

Using composer:

$ composer require juststeveking/http-slim

You are then free to use it as needed within your projects.

Next steps

The next step is to install a compliant package to do the request itself.

A few packages that are recommended:

Usage

Once you have installed a PSR-18 package and a PSR-17 package we do not need to do anything else. This package support HTTP Autodiscovery for your PSR compliant Client and Request factories. However, should you choose to inject you can do!

<?php

declare(strict_types=1);

use JustSteveKing\HttpSlim\HttpClient;
use Symfony\Component\HttpClient\Psr18Client;

// Injecting Clients: 
$httpClient = HttpClient::build(
    clientInterface: new Psr18Client(),
    requestFactory: new Psr18Client(),
    streamFactory: new Psr18Client(),
);

// Using HTTP Auto-discovery
$httpClient = HttpClient::build();


// perform a get request
$httpClient->get(
    uri: 'https://api.example.com/v1/resource',
);

// perform a post request
$httpClient->post(
    uri: 'https://api.example.com/v1/resource',
    body: ['foo' => 'bar'],
);

// perform a put request
$httpClient->put(
    uri: 'https://api.example.com/v1/resource/identifier',
    body: ['foo' => 'bar'],
);

// perform a patch request
$httpClient->patch(
    uri: 'https://api.example.com/v1/resource/identifier',
    body: ['foo' => 'bar'],
);

// perform a delete request
$httpClient->delete(
    uri: 'https://api.example.com/v1/resource/identifier',
);

// perform an options request
$httpClient->options(
    uri: 'https://api.example.com/v1/resource/identifier',
    headers: ['X-OPTIONAL' => 'headers'],
);

// Adding Plugins
$httpClient->addPlugin(
    plugin: new \Http\Client\Common\Plugin\HeaderDefaultsPlugin(
        headers: ['Content-Type' => 'application/json'],
    ),
);

Tests

There is a composer script available to run the tests:

$ composer run preflight:test

However, if you are unable to run this please use the following command:

$ ./vendor/bin/phpunit --testdox

Security

If you discover any security related issues, please email juststevemcd@gmail.com instead of using the issue tracker.

统计信息

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

GitHub 信息

  • Stars: 7
  • Watchers: 0
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-05-29