Add additional examples to cover supported request methods

This commit is contained in:
Zach Borboa
2016-10-12 08:06:15 -07:00
parent fada23bbba
commit 27abd4899a
8 changed files with 125 additions and 14 deletions
+25
View File
@@ -0,0 +1,25 @@
<?php
require __DIR__ . '/vendor/autoload.php';
use \Curl\Curl;
// curl --request DELETE "https://httpbin.org/delete?key=value" --data "a=1&b=2&c=3"
$curl = new Curl();
$curl->delete('https://httpbin.org/delete',
array(
'key' => 'value',
),
array(
'a' => '1',
'b' => '2',
'c' => '3',
)
);
if ($curl->error) {
echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
} else {
echo 'Data server received via DELETE:' . "\n";
var_dump($curl->response->form);
}
+5 -1
View File
@@ -3,8 +3,12 @@ require __DIR__ . '/vendor/autoload.php';
use \Curl\Curl;
// curl --request GET "https://httpbin.org/get?key=value"
$curl = new Curl();
$curl->get('https://httpbin.org/get');
$curl->get('https://httpbin.org/get', array(
'key' => 'value',
));
if ($curl->error) {
echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
+18
View File
@@ -0,0 +1,18 @@
<?php
require __DIR__ . '/vendor/autoload.php';
use \Curl\Curl;
// curl --head "http://127.0.0.1:8000/?key=value"
$curl = new Curl();
$curl->head('http://127.0.0.1:8000/', array(
'key' => 'value',
));
if ($curl->error) {
echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
} else {
echo 'Response headers:' . "\n";
var_dump($curl->responseHeaders);
}
+18
View File
@@ -0,0 +1,18 @@
<?php
require __DIR__ . '/vendor/autoload.php';
use \Curl\Curl;
// curl --get --request OPTIONS "http://127.0.0.1:8000/" --data "foo=bar"
$curl = new Curl();
$curl->options('http://127.0.0.1:8000/', array(
'foo' => 'bar',
));
if ($curl->error) {
echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
} else {
echo 'Response:' . "\n";
var_dump($curl->response);
}
+20
View File
@@ -0,0 +1,20 @@
<?php
require __DIR__ . '/vendor/autoload.php';
use \Curl\Curl;
// curl --request PATCH "https://httpbin.org/patch" --data "a=1&b=2&c=3"
$curl = new Curl();
$curl->patch('https://httpbin.org/patch', array(
'a' => '1',
'b' => '2',
'c' => '3',
));
if ($curl->error) {
echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
} else {
echo 'Response:' . "\n";
var_dump($curl->response);
}
+10 -9
View File
@@ -3,17 +3,18 @@ require __DIR__ . '/vendor/autoload.php';
use \Curl\Curl;
// curl \
// -X POST \
// -d "id=1&content=Hello+world%21&date=2015-06-30+19%3A42%3A21" \
// "https://httpbin.org/post"
// curl --request POST "https://httpbin.org/post" --data "id=1&content=Hello+world%21&date=2015-06-30+19%3A42%3A21"
$data = array(
$curl = new Curl();
$curl->post('https://httpbin.org/post', array(
'id' => '1',
'content' => 'Hello world!',
'date' => date('Y-m-d H:i:s'),
);
));
$curl = new Curl();
$curl->post('https://httpbin.org/post', $data);
var_dump($curl->response->form);
if ($curl->error) {
echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
} else {
echo 'Data server received via POST:' . "\n";
var_dump($curl->response->form);
}
+9 -4
View File
@@ -3,13 +3,18 @@ require __DIR__ . '/vendor/autoload.php';
use \Curl\Curl;
// curl -X PUT -d "id=1&first_name=Zach&last_name=Borboa" "https://httpbin.org/put"
// curl --request PUT "https://httpbin.org/put" --data "id=1&first_name=Zach&last_name=Borboa"
$curl = new Curl();
$curl->put('https://httpbin.org/put', array(
'id' => 1,
'id' => '1',
'first_name' => 'Zach',
'last_name' => 'Borboa',
));
echo 'Data server received via PUT:' . "\n";
var_dump($curl->response->form);
if ($curl->error) {
echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
} else {
echo 'Data server received via PUT:' . "\n";
var_dump($curl->response->form);
}
+20
View File
@@ -0,0 +1,20 @@
<?php
require __DIR__ . '/vendor/autoload.php';
use \Curl\Curl;
// curl --request SEARCH "http://127.0.0.1:8000/" --data "a=1&b=2&c=3"
$curl = new Curl();
$curl->search('http://127.0.0.1:8000/', array(
'a' => '1',
'b' => '2',
'c' => '3',
));
if ($curl->error) {
echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
} else {
echo 'Response:' . "\n";
var_dump($curl->response);
}