Skip to content

Commit dfbde44

Browse files
author
Grégoire Paris
committed
Document the most common usage of HTTPlug
I've seen several people complaining on this section being empty, and had no idea how to fill it, until today, when I wanted to write a smoke test for my application and had to figure it out. Hopefully this will get more people into HTTPlug.
1 parent 60bfe9b commit dfbde44

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)