Skip to content

Commit

Permalink
add example for post request
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Oct 31, 2022
1 parent 4415d90 commit bfe5b89
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
4 changes: 2 additions & 2 deletions examples/get.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
// First, include the Composer Autoloader.
require_once dirname(__DIR__) . '/vendor/autoload.php';

// First, create the HTTP client
// Next, create the HTTP client
$client = new \Art4\Requests\Psr\HttpClient();

// Next, create the HTTP request
$request = $client->createRequest('GET', 'http://httpbin.org/get');
$request = $client->createRequest(\WpOrg\Requests\Requests::GET, 'http://httpbin.org/get');

// You can set headers in PSR-7 style
$request = $request->withAddedHeader('Accept', 'application/json');
Expand Down
24 changes: 24 additions & 0 deletions examples/post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

// First, include the Composer Autoloader.
require_once dirname(__DIR__) . '/vendor/autoload.php';

// Next, create the HTTP client
$client = new \Art4\Requests\Psr\HttpClient();

// Next, create the HTTP request
$request = $client->createRequest(\WpOrg\Requests\Requests::POST, 'http://httpbin.org/post');

// You can set headers in PSR-7 style
$request = $request->withAddedHeader('Accept', 'application/json');

// You can set form data as body
$request = $request->withBody($client->createStream(
http_build_query(['mydata' => 'something'])
));

// Now let's make a request!
$response = $client->sendRequest($request);

// Check what we received
var_dump($response);
4 changes: 2 additions & 2 deletions tests/Psr/HttpClient/HttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
use Art4\Requests\Exception\Psr\ClientException;
use Art4\Requests\Exception\Psr\NetworkException;
use Art4\Requests\Exception\Psr\RequestException;
use WpOrg\Requests\Exception\Transport as ExceptionTransport;
use Art4\Requests\Psr\HttpClient;
use Psr\Http\Message\ResponseInterface;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;
use WpOrg\Requests\Exception\Transport as ExceptionTransport;
use WpOrg\Requests\Transport;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;

final class HttpClientTest extends TestCase
{
Expand Down

0 comments on commit bfe5b89

Please sign in to comment.