PHP code example of indragunawan / rest-service

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

    

indragunawan / rest-service example snippets




// httpbin-v1.php

return [
    'name' => 'httpbin API',
    'endpoint' => '{endpoint}',
    'defaults' => [
        'endpoint' => [
            'rule' => ' uri, query, body
            'requestUri' => '/post',
            'request' => [
                'type' => 'map', // map, list
                'members' => [
                    'Name' => [
                        'locationName' => 'name',
                        'type' => 'string', // string, integer, float, number, boolean, datetime
                        'rule' => '

use IndraGunawan\RestService\ServiceClient;

    $config = [
        'httpClient' => [
            // use by GuzzleClient
        ],
        'defaults' => [
            // default value for services specification
        ],
    ];
    $cacheDir = __DIR__.'/../cache'; // optional, default: null
    $debug = false; // optional, default: false

    $service = new ServiceClient(__DIR__.'/httpbin-v1.php', $config, $cacheDir, $debug);
    $result = $service->postTest([
        'Name' => 'My Name',
    ]);

    echo $result['url']; // format_http://httpbin.org/post
    // var_dump($result->toArray());