• Stars
    star
    1,224
  • Rank 36,775 (Top 0.8 %)
  • Language
    PHP
  • License
    MIT License
  • Created almost 9 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Finds installed clients and message factories

HTTPlug Discovery

Latest Version Software License Tests Code Coverage Quality Score Total Downloads

This library provides auto-discovery and auto-installation of well-known PSR-17, PSR-18 and HTTPlug implementations.

Install

Via Composer

composer require php-http/discovery

Usage as a library author

Please see the official documentation.

If your library/SDK needs a PSR-18 client, here is a quick example.

First, you need to install a PSR-18 client and a PSR-17 factory implementations. This should be done only for dev dependencies as you don't want to force a specific implementation on your users:

composer require --dev symfony/http-client
composer require --dev nyholm/psr7

Then, you can disable the Composer plugin embeded in php-http/discovery because you just installed the dev dependencies you need for testing:

composer config allow-plugins.php-http/discovery false

Finally, you need to require php-http/discovery and the generic implementations that your library is going to need:

composer require 'php-http/discovery:^1.17'
composer require 'psr/http-client-implementation:*'
composer require 'psr/http-factory-implementation:*'

Now, you're ready to make an HTTP request:

use Http\Discovery\Psr18Client;

$client = new Psr18Client();

$request = $client->createRequest('GET', 'https://example.com');
$response = $client->sendRequest($request);

Internally, this code will use whatever PSR-7, PSR-17 and PSR-18 implementations that your users have installed.

Usage as a library user

If you use a library/SDK that requires php-http/discovery, you can configure the auto-discovery mechanism to use a specific implementation when many are available in your project.

For example, if you have both nyholm/psr7 and guzzlehttp/guzzle in your project, you can tell php-http/discovery to use guzzlehttp/guzzle instead of nyholm/psr7 by running the following command:

composer config extra.discovery.psr/http-factory-implementation GuzzleHttp\\Psr7\\HttpFactory

This will update your composer.json file to add the following configuration:

{
    "extra": {
        "discovery": {
            "psr/http-factory-implementation": "GuzzleHttp\\Psr7\\HttpFactory"
        }
    }
}

Don't forget to run composer install to apply the changes, and ensure that the composer plugin is enabled:

composer config allow-plugins.php-http/discovery true
composer install

Testing

composer test

Contributing

Please see our contributing guide.

Security

If you discover any security related issues, please contact us at [email protected].

License

The MIT License (MIT). Please see License File for more information.

More Repositories

1

httplug

HTTPlug, the HTTP client abstraction for PHP
PHP
2,527
star
2

promise

Promise used for asynchronous HTTP requests
PHP
1,759
star
3

guzzle6-adapter

Guzzle 6 HTTP adapter
PHP
1,375
star
4

message-factory

Abandoned: Httplug Factory interfaces for PSR-7 HTTP Message
PHP
1,353
star
5

message

HTTP Message related tools
PHP
1,257
star
6

client-common

Common HTTP Client implementations and tools for HTTPlug
PHP
976
star
7

curl-client

cURL client
PHP
432
star
8

HttplugBundle

Symfony Framework Integration for HTTPlug
PHP
381
star
9

logger-plugin

PSR-3 Logger plugin for HTTPlug
PHP
283
star
10

stopwatch-plugin

Symfony Stopwatch plugin for HTTPlug
PHP
261
star
11

cache-plugin

PSR-6 Cache plugin for HTTPlug
PHP
248
star
12

multipart-stream-builder

Build a multipart stream independently form any PSR7 Stream implementation
PHP
246
star
13

socket-client

Socket HTTP Client
PHP
77
star
14

guzzle7-adapter

Guzzle 7 adapter
PHP
68
star
15

mock-client

Mock HTTP client
PHP
67
star
16

psr7-integration-tests

PHP
40
star
17

httplug-flex-pack

A "pack" recipe for Symfony flex
39
star
18

documentation

Documentation for PHP-HTTP including HTTPlug
Python
23
star
19

react-adapter

React HTTP Adapter
PHP
19
star
20

vcr-plugin

Record your test suite's HTTP interactions and replay them during future test runs.
PHP
19
star
21

client-integration-tests

HTTP client integration tests
PHP
16
star
22

awesome-http

A curated list of amazingly awesome PHP libraries, resources and shiny things related to HTTP
14
star
23

laravel-httplug

Laravel package for HTTPlug
PHP
12
star
24

plugins

[DEPRECATED] Plugin client, decorate HTTP client with middlewares
PHP
11
star
25

guzzle5-adapter

Guzzle 5 HTTP adapter
PHP
10
star
26

artax-adapter

Artax HTTP Adapter
PHP
5
star
27

cakephp-adapter

CakePHP Adapter for HTTPlug
PHP
5
star
28

demo-library

PHP
3
star
29

httplug-async

[DEPRECATED] HTTPlug Async, the HTTP asynchronous client abstraction for PHP http://httplug.io
PHP
3
star
30

boilerplate

Boilerplate for packages
PHP
3
star
31

buzz-adapter

Buzz HTTP adapter
PHP
3
star
32

httplug.github.io

HTTPlug website
JavaScript
3
star
33

zend-adapter

Zend Adapter for HTTPlug
PHP
2
star
34

.github

Default community health files
2
star
35

utils

[DEPRECATED] HTTP Client Utilities
PHP
2
star
36

throttle-plugin

PHP-HTTP plugin for throttling/rate limiting with the symfony/rate-limiter
PHP
2
star
37

random-host-plugin

Client-side round robin load balancer plugin for HTTPlug
PHP
1
star
38

helper

[DEPRECATED] Helper classes for HTTP related data
PHP
1
star
39

adapter-integration-tests

[DEPRECATED] Please use https://github.com/php-http/client-integration-tests
PHP
1
star
40

httplug-stream-wrapper

PHP
1
star
41

api.php-http.org

API documentation for PHP HTTP projects
HTML
1
star