PHP code example of nacosvel / openapi

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

    

nacosvel / openapi example snippets


use Nacosvel\OpenAPI\Builder;

$instance = Builder::factory([
    'mchid' => '190000****',
], [
    'base_uri' => 'https://httpspot.dev/',
]);

use Nacosvel\OpenAPI\Middleware\Middleware;

$instance->addMiddleware([
    new Middleware($builder->getClientDecorator()->getConfig()),
]);

$response = $builder->chain('anything/{code}')->get([
    'query' => [
        'id' => 1,
    ],
    'code'  => rand(100000, 999999),
]);

var_dump($response->getBody()->getContents());

use Psr\Http\Message\ResponseInterface;

$response = $builder->anything->_code_->getAsync([
    'query' => [
        'id' => 1,
    ],
    'code'  => rand(100000, 999999),
])->then(function (ResponseInterface $response) {
    return $response->getBody()->getContents();
})->wait();

var_dump($response);