1. Go to this page and download the library: Download bigoen/api-bridge 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/ */
bigoen / api-bridge example snippets
namespace App\Model;
class Example
{
public ?string $name = null;
public ?string $email = null;
}
namespace App\Model;
class Error
{
public ?string $status = null;
public ?string $message = null;
}
use App\Model\Example;
use App\Model\Error;
use Symfony\Component\HttpClient\HttpClient;
use Bigoen\ApiBridge\HttpClient\SimpleClient;
$httpClient = HttpClient::create();
$client = new SimpleClient($httpClient);
$client
->setBaseUrl("http://example.com")
->setClass(Example::class)
->setThrowClass(Error:class)
->setOptions([
// Set http client request options.
]);
// all objects.
$client->setPath("/api/examples")->getAll();
// get object with id.
$client->setPath("/api/examples/{id}")->setId(1)->get();
// post object.
$model = new Example();
$model->name = 'Test';
$model->email = '[email protected]';
$postModel = $client->setPath("/api/examples")->post($model);
// put object.
$model = $client->setPath("/api/examples/{id}")->setId(1)->get();
$model->name = 'New Name';
$model = $client->setPath("/api/examples/{id}")->put($model);
// delete object.
$isDelete = $client->setPath("/api/examples/{id}")->setId(1)->delete();
namespace App\Model;
use Bigoen\ApiBridge\Bridge\ApiPlatform\Model\Traits\JsonldModelTrait;
class Example
{
use JsonldModelTrait;
public ?string $name = null;
public ?string $email = null;
}
use App\Model\Example;
use Symfony\Component\HttpClient\HttpClient;
use Bigoen\ApiBridge\Bridge\ApiPlatform\HttpClient\JsonldClient;
$httpClient = HttpClient::create();
$client = new JsonldClient($httpClient);
$client
->setBaseUrl("http://example.com")
->setClass(Example::class)
->setOptions([
// Set http client request options.
]);
// all objects.
$pageOne = $client->setPath("/api/examples")->getAll();
// get next page objects.
$pageTwo = $client->setPath($pageOne->nextPagePath)->getAll();
// get object with id.
$client->setPath("/api/examples/{id}")->setId(1)->get();
// post object.
$model = new Example();
$model->name = 'Test';
$model->email = '[email protected]';
$postModel = $client->setPath("/api/examples")->post($model);
// put object.
$model = $client->setPath("/api/examples/{id}")->setId(1)->get();
$model->name = 'New Name';
$model = $client->setPath("/api/examples/{id}")->put($model);
// delete object.
$isDelete = $client->setPath("/api/examples/{id}")->setId(1)->delete();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.