Skip to content

Commit e5e4e0c

Browse files
authored
Merge pull request #227 from greg0ire/lower_the_barrier
Document the most common usage of HTTPlug
2 parents caac450 + dfbde44 commit e5e4e0c

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

httplug/tutorial.rst

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,22 @@ Create a file ``demo.php`` in the root folder and write the following code::
4040
<?php
4141
require('vendor/autoload.php');
4242

43-
TODO: create client instance with discovery and do some requests
43+
use Http\Discovery\HttpClientDiscovery;
44+
use Http\Discovery\MessageFactoryDiscovery;
4445

46+
$client = HttpClientDiscovery::find();
47+
$messageFactory = MessageFactoryDiscovery::find();
48+
$homeResponse = $client->sendRequest(
49+
$messageFactory->createRequest('GET', 'http://httplug.io')
50+
);
51+
52+
var_dump($homeResponse->getStatusCode()); // 200, hopefully
53+
54+
$missingPageResponse = $client->sendRequest(
55+
$messageFactory->createRequest('GET', 'http://httplug.io/missingPage')
56+
);
57+
58+
var_dump($missingPageResponse->getStatusCode()); // 404
4559

4660
Using an Asynchronous Client
4761
----------------------------

0 commit comments

Comments
 (0)