PHP code example of edgvi10 / integration-controller
1. Go to this page and download the library: Download edgvi10/integration-controller 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/ */
edgvi10 / integration-controller example snippets
use EDGVI10\Controllers\IntegrationController;
// Inicialização simples
$client = new IntegrationController();
// Inicialização com configurações
$client = new IntegrationController([
'baseURL' => 'https://api.example.com',
'headers' => ['Accept' => 'application/json'],
'timeout' => 30,
'verifySSL' => true,
'userAgent' => 'MyApp/1.0'
]);
$client = new IntegrationController([
'baseURL' => 'https://api.example.com'
]);
// Fazer uma requisição GET
if ($client->get('/users', ['page' => 1, 'limit' => 10])) {
$data = $client->jsonResponse();
print_r($data);
} else {
echo "Erro: " . $client->lastError;
}
$client = new IntegrationController([
'baseURL' => 'https://api.example.com'
]);
$client->setMethod('GET')
->setEndpoint('/unstable-endpoint');
// Tenta até 5 vezes com 2 segundos de intervalo
if ($client->sendWithRetry(5, 2)) {
echo "Requisição bem-sucedida após tentativas!";
} else {
echo "Falhou após todas as tentativas";
}
$client = new IntegrationController([
'baseURL' => 'https://api.example.com'
]);
if ($client->get('/users/123')) {
// Status code
echo "Status: " . $client->responseStatusCode . "\n";
// Body bruto
echo "Body: " . $client->responseBody . "\n";
// JSON decodificado
$data = $client->jsonResponse();
print_r($data);
// Headers
print_r($client->responseHeaders);
// Endpoint usado
echo "Endpoint: " . $client->responseEndpoint;
}
$client = new IntegrationController([
'baseURL' => 'https://api.example.com'
]);
// Primeira requisição
$client->get('/users');
$users = $client->jsonResponse();
// Limpar estado antes da próxima requisição
$client->clear();
// Segunda requisição
$client->get('/products');
$products = $client->jsonResponse();