{"action":"created","comment":{"url":"https://api.github.com/repos/php-http/documentation/pulls/comments/74684381","id":74684381,"diff_hunk":"@@ -152,3 +152,66 @@ RandomClientPool\n ****************\n \n ``RandomClientPool`` randomly choose an available client, throw a ``NotFoundHttpClientException`` if none are available.\n+\n+\n+HTTP Client Router\n+------------------\n+\n+This client accepts pairs of clients (both sync and async) and request matchers.\n+Every request is \"routed\" through this single client, checked against the request matchers\n+and sent using the first matched client. If there is no matching client, an exception is thrown.\n+\n+This allows a single client to be used for different requests.\n+\n+In the following example we use the client router to access an API protected by basic auth\n+and also to download an image from a static host::\n+\n+    use Http\\Client\\Common\\HttpClientRouter;\n+    use Http\\Client\\Common\\PluginClient;\n+    use Http\\Client\\Common\\Plugin\\AuthenticationPlugin;\n+    use Http\\Discovery\\HttpClientDiscovery;\n+    use Http\\Discovery\\MessageFactoryDiscovery;\n+    use Http\\Message\\Authentication\\BasicAuth;\n+    use Http\\Message\\RequestMatcher\\RequestMatcher;\n+\n+    $client = new HttpClientRouter();\n+\n+    $requestMatcher = new RequestMatcher(null, 'api.example.com');\n+    $pluginClient = new PluginClient(\n+        HttpClientDiscovery::find(),\n+        [new AuthenticationPlugin(new BasicAuth('user', 'password'))]\n+    );\n+\n+    $client->addClient($pluginClient, $requestMatcher);\n+\n+\n+    $requestMatcher = new RequestMatcher(null, 'images.example.com');\n+\n+    $client->addClient(HttpClientDiscovery::find(), $requestMatcher);\n+\n+\n+    $messageFactory = MessageFactoryDiscovery::find();\n+\n+    // Get the user data\n+    $request = $messageFactory->createRequest('GET', 'https://api.example.com/user/1');\n+\n+    $response = $client->send($request);\n+    $imagePath = json_decode((string) $response->getBody(), true)['image_path'];\n+\n+    // Download the image\n+    $request = $messageFactory->createRequest('GET', 'https://images.example.com/user/'.$imagePath);\n+\n+    $response = $client->send($request);\n+\n+    file_put_contents('path/to/images/'.$imagePath, (string) $response->getBody());\n+\n+    $request = $messageFactory->createRequest('GET', 'https://api2.example.com/user/1');\n+\n+    // Throws an Http\\Client\\Exception\\RequestException\n+    $client->send($request);\n+\n+\n+.. note::\n+\n+    Simple routing can be achieved with the ``RequestConditionalPlugin`` and the ``PluginClient``,\n+    but in that case the routing logic is integrated into the linear request flow.","path":"components/client-common.rst","position":66,"original_position":66,"commit_id":"52fb541a66dc103d3745a76def79cdbf875169ce","original_commit_id":"52fb541a66dc103d3745a76def79cdbf875169ce","user":{"login":"dbu","id":76576,"avatar_url":"https://avatars.githubusercontent.com/u/76576?v=3","gravatar_id":"","url":"https://api.github.com/users/dbu","html_url":"https://github.com/dbu","followers_url":"https://api.github.com/users/dbu/followers","following_url":"https://api.github.com/users/dbu/following{/other_user}","gists_url":"https://api.github.com/users/dbu/gists{/gist_id}","starred_url":"https://api.github.com/users/dbu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbu/subscriptions","organizations_url":"https://api.github.com/users/dbu/orgs","repos_url":"https://api.github.com/users/dbu/repos","events_url":"https://api.github.com/users/dbu/events{/privacy}","received_events_url":"https://api.github.com/users/dbu/received_events","type":"User","site_admin":false},"body":"maybe say:\r\n\r\nThe example above could also be solved using the RequestConditionalPlugin to only apply the BasicAuthPlugin for the api domain. The HttpClientRouter is for situations where you need different plugin chains for different requests.","created_at":"2016-08-13T09:03:06Z","updated_at":"2016-08-13T09:03:06Z","html_url":"https://github.com/php-http/documentation/pull/103#discussion_r74684381","pull_request_url":"https://api.github.com/repos/php-http/documentation/pulls/103","_links":{"self":{"href":"https://api.github.com/repos/php-http/documentation/pulls/comments/74684381"},"html":{"href":"https://github.com/php-http/documentation/pull/103#discussion_r74684381"},"pull_request":{"href":"https://api.github.com/repos/php-http/documentation/pulls/103"}}},"pull_request":{"url":"https://api.github.com/repos/php-http/documentation/pulls/103","id":64687750,"html_url":"https://github.com/php-http/documentation/pull/103","diff_url":"https://github.com/php-http/documentation/pull/103.diff","patch_url":"https://github.com/php-http/documentation/pull/103.patch","issue_url":"https://api.github.com/repos/php-http/documentation/issues/103","number":103,"state":"open","locked":false,"title":"Add documentation for HTTP Client router","user":{"login":"sagikazarmark","id":1226384,"avatar_url":"https://avatars.githubusercontent.com/u/1226384?v=3","gravatar_id":"","url":"https://api.github.com/users/sagikazarmark","html_url":"https://github.com/sagikazarmark","followers_url":"https://api.github.com/users/sagikazarmark/followers","following_url":"https://api.github.com/users/sagikazarmark/following{/other_user}","gists_url":"https://api.github.com/users/sagikazarmark/gists{/gist_id}","starred_url":"https://api.github.com/users/sagikazarmark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sagikazarmark/subscriptions","organizations_url":"https://api.github.com/users/sagikazarmark/orgs","repos_url":"https://api.github.com/users/sagikazarmark/repos","events_url":"https://api.github.com/users/sagikazarmark/events{/privacy}","received_events_url":"https://api.github.com/users/sagikazarmark/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-03-30T20:02:35Z","updated_at":"2016-08-13T09:03:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c3e93a985626ffee3e520ddade0080e2098eb975","assignee":{"login":"sagikazarmark","id":1226384,"avatar_url":"https://avatars.githubusercontent.com/u/1226384?v=3","gravatar_id":"","url":"https://api.github.com/users/sagikazarmark","html_url":"https://github.com/sagikazarmark","followers_url":"https://api.github.com/users/sagikazarmark/followers","following_url":"https://api.github.com/users/sagikazarmark/following{/other_user}","gists_url":"https://api.github.com/users/sagikazarmark/gists{/gist_id}","starred_url":"https://api.github.com/users/sagikazarmark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sagikazarmark/subscriptions","organizations_url":"https://api.github.com/users/sagikazarmark/orgs","repos_url":"https://api.github.com/users/sagikazarmark/repos","events_url":"https://api.github.com/users/sagikazarmark/events{/privacy}","received_events_url":"https://api.github.com/users/sagikazarmark/received_events","type":"User","site_admin":false},"assignees":[{"login":"sagikazarmark","id":1226384,"avatar_url":"https://avatars.githubusercontent.com/u/1226384?v=3","gravatar_id":"","url":"https://api.github.com/users/sagikazarmark","html_url":"https://github.com/sagikazarmark","followers_url":"https://api.github.com/users/sagikazarmark/followers","following_url":"https://api.github.com/users/sagikazarmark/following{/other_user}","gists_url":"https://api.github.com/users/sagikazarmark/gists{/gist_id}","starred_url":"https://api.github.com/users/sagikazarmark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sagikazarmark/subscriptions","organizations_url":"https://api.github.com/users/sagikazarmark/orgs","repos_url":"https://api.github.com/users/sagikazarmark/repos","events_url":"https://api.github.com/users/sagikazarmark/events{/privacy}","received_events_url":"https://api.github.com/users/sagikazarmark/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/php-http/documentation/pulls/103/commits","review_comments_url":"https://api.github.com/repos/php-http/documentation/pulls/103/comments","review_comment_url":"https://api.github.com/repos/php-http/documentation/pulls/comments{/number}","comments_url":"https://api.github.com/repos/php-http/documentation/issues/103/comments","statuses_url":"https://api.github.com/repos/php-http/documentation/statuses/52fb541a66dc103d3745a76def79cdbf875169ce","head":{"label":"php-http:http_client_router","ref":"http_client_router","sha":"52fb541a66dc103d3745a76def79cdbf875169ce","user":{"login":"php-http","id":12104859,"avatar_url":"https://avatars.githubusercontent.com/u/12104859?v=3","gravatar_id":"","url":"https://api.github.com/users/php-http","html_url":"https://github.com/php-http","followers_url":"https://api.github.com/users/php-http/followers","following_url":"https://api.github.com/users/php-http/following{/other_user}","gists_url":"https://api.github.com/users/php-http/gists{/gist_id}","starred_url":"https://api.github.com/users/php-http/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/php-http/subscriptions","organizations_url":"https://api.github.com/users/php-http/orgs","repos_url":"https://api.github.com/users/php-http/repos","events_url":"https://api.github.com/users/php-http/events{/privacy}","received_events_url":"https://api.github.com/users/php-http/received_events","type":"Organization","site_admin":false},"repo":{"id":37063526,"name":"documentation","full_name":"php-http/documentation","owner":{"login":"php-http","id":12104859,"avatar_url":"https://avatars.githubusercontent.com/u/12104859?v=3","gravatar_id":"","url":"https://api.github.com/users/php-http","html_url":"https://github.com/php-http","followers_url":"https://api.github.com/users/php-http/followers","following_url":"https://api.github.com/users/php-http/following{/other_user}","gists_url":"https://api.github.com/users/php-http/gists{/gist_id}","starred_url":"https://api.github.com/users/php-http/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/php-http/subscriptions","organizations_url":"https://api.github.com/users/php-http/orgs","repos_url":"https://api.github.com/users/php-http/repos","events_url":"https://api.github.com/users/php-http/events{/privacy}","received_events_url":"https://api.github.com/users/php-http/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/php-http/documentation","description":"Documentation for PHP-HTTP including HTTPlug","fork":false,"url":"https://api.github.com/repos/php-http/documentation","forks_url":"https://api.github.com/repos/php-http/documentation/forks","keys_url":"https://api.github.com/repos/php-http/documentation/keys{/key_id}","collaborators_url":"https://api.github.com/repos/php-http/documentation/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/php-http/documentation/teams","hooks_url":"https://api.github.com/repos/php-http/documentation/hooks","issue_events_url":"https://api.github.com/repos/php-http/documentation/issues/events{/number}","events_url":"https://api.github.com/repos/php-http/documentation/events","assignees_url":"https://api.github.com/repos/php-http/documentation/assignees{/user}","branches_url":"https://api.github.com/repos/php-http/documentation/branches{/branch}","tags_url":"https://api.github.com/repos/php-http/documentation/tags","blobs_url":"https://api.github.com/repos/php-http/documentation/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/php-http/documentation/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/php-http/documentation/git/refs{/sha}","trees_url":"https://api.github.com/repos/php-http/documentation/git/trees{/sha}","statuses_url":"https://api.github.com/repos/php-http/documentation/statuses/{sha}","languages_url":"https://api.github.com/repos/php-http/documentation/languages","stargazers_url":"https://api.github.com/repos/php-http/documentation/stargazers","contributors_url":"https://api.github.com/repos/php-http/documentation/contributors","subscribers_url":"https://api.github.com/repos/php-http/documentation/subscribers","subscription_url":"https://api.github.com/repos/php-http/documentation/subscription","commits_url":"https://api.github.com/repos/php-http/documentation/commits{/sha}","git_commits_url":"https://api.github.com/repos/php-http/documentation/git/commits{/sha}","comments_url":"https://api.github.com/repos/php-http/documentation/comments{/number}","issue_comment_url":"https://api.github.com/repos/php-http/documentation/issues/comments{/number}","contents_url":"https://api.github.com/repos/php-http/documentation/contents/{+path}","compare_url":"https://api.github.com/repos/php-http/documentation/compare/{base}...{head}","merges_url":"https://api.github.com/repos/php-http/documentation/merges","archive_url":"https://api.github.com/repos/php-http/documentation/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/php-http/documentation/downloads","issues_url":"https://api.github.com/repos/php-http/documentation/issues{/number}","pulls_url":"https://api.github.com/repos/php-http/documentation/pulls{/number}","milestones_url":"https://api.github.com/repos/php-http/documentation/milestones{/number}","notifications_url":"https://api.github.com/repos/php-http/documentation/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/php-http/documentation/labels{/name}","releases_url":"https://api.github.com/repos/php-http/documentation/releases{/id}","deployments_url":"https://api.github.com/repos/php-http/documentation/deployments","created_at":"2015-06-08T11:44:22Z","updated_at":"2016-02-29T15:02:39Z","pushed_at":"2016-08-13T08:45:50Z","git_url":"git://github.com/php-http/documentation.git","ssh_url":"git@github.com:php-http/documentation.git","clone_url":"https://github.com/php-http/documentation.git","svn_url":"https://github.com/php-http/documentation","homepage":"http://docs.php-http.org","size":2349,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":11,"mirror_url":null,"open_issues_count":22,"forks":11,"open_issues":22,"watchers":1,"default_branch":"master"}},"base":{"label":"php-http:master","ref":"master","sha":"f7e64e0161576829ecf942b0d2a153075a822e22","user":{"login":"php-http","id":12104859,"avatar_url":"https://avatars.githubusercontent.com/u/12104859?v=3","gravatar_id":"","url":"https://api.github.com/users/php-http","html_url":"https://github.com/php-http","followers_url":"https://api.github.com/users/php-http/followers","following_url":"https://api.github.com/users/php-http/following{/other_user}","gists_url":"https://api.github.com/users/php-http/gists{/gist_id}","starred_url":"https://api.github.com/users/php-http/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/php-http/subscriptions","organizations_url":"https://api.github.com/users/php-http/orgs","repos_url":"https://api.github.com/users/php-http/repos","events_url":"https://api.github.com/users/php-http/events{/privacy}","received_events_url":"https://api.github.com/users/php-http/received_events","type":"Organization","site_admin":false},"repo":{"id":37063526,"name":"documentation","full_name":"php-http/documentation","owner":{"login":"php-http","id":12104859,"avatar_url":"https://avatars.githubusercontent.com/u/12104859?v=3","gravatar_id":"","url":"https://api.github.com/users/php-http","html_url":"https://github.com/php-http","followers_url":"https://api.github.com/users/php-http/followers","following_url":"https://api.github.com/users/php-http/following{/other_user}","gists_url":"https://api.github.com/users/php-http/gists{/gist_id}","starred_url":"https://api.github.com/users/php-http/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/php-http/subscriptions","organizations_url":"https://api.github.com/users/php-http/orgs","repos_url":"https://api.github.com/users/php-http/repos","events_url":"https://api.github.com/users/php-http/events{/privacy}","received_events_url":"https://api.github.com/users/php-http/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/php-http/documentation","description":"Documentation for PHP-HTTP including HTTPlug","fork":false,"url":"https://api.github.com/repos/php-http/documentation","forks_url":"https://api.github.com/repos/php-http/documentation/forks","keys_url":"https://api.github.com/repos/php-http/documentation/keys{/key_id}","collaborators_url":"https://api.github.com/repos/php-http/documentation/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/php-http/documentation/teams","hooks_url":"https://api.github.com/repos/php-http/documentation/hooks","issue_events_url":"https://api.github.com/repos/php-http/documentation/issues/events{/number}","events_url":"https://api.github.com/repos/php-http/documentation/events","assignees_url":"https://api.github.com/repos/php-http/documentation/assignees{/user}","branches_url":"https://api.github.com/repos/php-http/documentation/branches{/branch}","tags_url":"https://api.github.com/repos/php-http/documentation/tags","blobs_url":"https://api.github.com/repos/php-http/documentation/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/php-http/documentation/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/php-http/documentation/git/refs{/sha}","trees_url":"https://api.github.com/repos/php-http/documentation/git/trees{/sha}","statuses_url":"https://api.github.com/repos/php-http/documentation/statuses/{sha}","languages_url":"https://api.github.com/repos/php-http/documentation/languages","stargazers_url":"https://api.github.com/repos/php-http/documentation/stargazers","contributors_url":"https://api.github.com/repos/php-http/documentation/contributors","subscribers_url":"https://api.github.com/repos/php-http/documentation/subscribers","subscription_url":"https://api.github.com/repos/php-http/documentation/subscription","commits_url":"https://api.github.com/repos/php-http/documentation/commits{/sha}","git_commits_url":"https://api.github.com/repos/php-http/documentation/git/commits{/sha}","comments_url":"https://api.github.com/repos/php-http/documentation/comments{/number}","issue_comment_url":"https://api.github.com/repos/php-http/documentation/issues/comments{/number}","contents_url":"https://api.github.com/repos/php-http/documentation/contents/{+path}","compare_url":"https://api.github.com/repos/php-http/documentation/compare/{base}...{head}","merges_url":"https://api.github.com/repos/php-http/documentation/merges","archive_url":"https://api.github.com/repos/php-http/documentation/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/php-http/documentation/downloads","issues_url":"https://api.github.com/repos/php-http/documentation/issues{/number}","pulls_url":"https://api.github.com/repos/php-http/documentation/pulls{/number}","milestones_url":"https://api.github.com/repos/php-http/documentation/milestones{/number}","notifications_url":"https://api.github.com/repos/php-http/documentation/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/php-http/documentation/labels{/name}","releases_url":"https://api.github.com/repos/php-http/documentation/releases{/id}","deployments_url":"https://api.github.com/repos/php-http/documentation/deployments","created_at":"2015-06-08T11:44:22Z","updated_at":"2016-02-29T15:02:39Z","pushed_at":"2016-08-13T08:45:50Z","git_url":"git://github.com/php-http/documentation.git","ssh_url":"git@github.com:php-http/documentation.git","clone_url":"https://github.com/php-http/documentation.git","svn_url":"https://github.com/php-http/documentation","homepage":"http://docs.php-http.org","size":2349,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":11,"mirror_url":null,"open_issues_count":22,"forks":11,"open_issues":22,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/php-http/documentation/pulls/103"},"html":{"href":"https://github.com/php-http/documentation/pull/103"},"issue":{"href":"https://api.github.com/repos/php-http/documentation/issues/103"},"comments":{"href":"https://api.github.com/repos/php-http/documentation/issues/103/comments"},"review_comments":{"href":"https://api.github.com/repos/php-http/documentation/pulls/103/comments"},"review_comment":{"href":"https://api.github.com/repos/php-http/documentation/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/php-http/documentation/pulls/103/commits"},"statuses":{"href":"https://api.github.com/repos/php-http/documentation/statuses/52fb541a66dc103d3745a76def79cdbf875169ce"}}}}
{"actor":{"display_login":"dbu"}}