PHP code example of battis / educoder-pest-fork

1. Go to this page and download the library: Download battis/educoder-pest-fork library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

battis / educoder-pest-fork example snippets



    $pest = new Pest('http://example.com');

    $thing = $pest->get('/things');

    $thing = $pest->post('/things', 
    	array(
    		'name' => "Foo",
    		'colour' => "Red"
    	)
    );

    $thing = $pest->put('/things/15',
    	array(
    		'colour' => "Blue"
    	)
    );

    $pest->delete('/things/15');

    


    try {
    	$thing = $pest->get('/things/18');
    } catch (Pest_NotFound $e) {
    	// 404
    	echo "Thing with ID 18 doesn't exist!";
    }

    try {
    	$thing = $pest->post('/things',  array('colour' => "Red"));
    } catch (Pest_InvalidRecord $e) {
    	// 422
    	echo "Data for Thing is invalid because: ".$e->getMessage();
    }

    


	$pest = new Pest('http://example.com');

	$things = $pest->get('/things.xml');

	$colours = $things->xpath('//colour');
	foreach($colours as $colour) {
		echo $colour."\n";
	}