PHP code example of satahippy / fake-api-server

1. Go to this page and download the library: Download satahippy/fake-api-server 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/ */

    

satahippy / fake-api-server example snippets


$provider = new RouterDataProvider([
    // limit and offset parameters only make sense
    '/local/articles[/]' => new PathDataProvider($filesystem, ['limit', 'offset']),
    // all other local data get from local data folder
    '/local/{trail:.*}' => new PathDataProvider($filesystem),
    // all r get from reddit (try request /r/PHP/hot.json)
    // requested every time cause of VoidCache
    '/r/{stub:.*}.json' => new ProxyDataProvider($redditGuzzle, $voidCache),
    // all r get from reddit (try request /get?your=paramter)
    '/get{stub:.*}' => new ProxyDataProvider($httpbinGuzzle, $cache),
    // all r get from reddit (try request /post?your=paramter with POST)
    '/post{stub:.*}' => new ProxyDataProvider($httpbinGuzzle, $cache)
]);

$data = $provider->data($request);

$provider = new FileDataProvider($filesystem, 'path/to/the/file.json');
$data = $provider->data($request);

$filesystem = new Filesystem(new Local(__DIR__ . '/data'));
$provider = new PathDataProvider($filesystem, ['page']);
$data = $provider->data($request);

$cache = new FilesystemCache(__DIR__ . '/cache');
$voidCache = new VoidCache();
$filesystem = new Filesystem(new Local(__DIR__ . '/data'));
$redditGuzzle = new GuzzleHttp\Client(['base_uri' => 'https://www.reddit.com']);
$httpbinGuzzle = new GuzzleHttp\Client(['base_uri' => 'http://httpbin.org']);

// request everytime cause of VoidCache
$redditProvider = new ProxyDataProvider($redditGuzzle, $voidCache);
// request only once an save to the FilesystemCache
$httpbinProvider = new ProxyDataProvider($httpbinGuzzle, $cache);