PHP code example of endpot / php-rest-proxy

1. Go to this page and download the library: Download endpot/php-rest-proxy 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/ */

    

endpot / php-rest-proxy example snippets


// create proxy instance
$proxy = new \Proxy\Proxy();

// set target url
$targetUrl = 'http://httpbin.org/';

// create psr7 request based on the global parameters
$request = $proxy->fromGlobals();

// add middlewares
// forward request to target
$response = $proxy->addMiddleware('ExampleMiddleware')
    ->forward($request)
    ->to($targetUrl);
    
// get and show the response
echo $response->getBody();