Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/bigoen/api-bridge

Bridges for api projects.
https://github.com/bigoen/api-bridge

api api-bridge http-client json jsonld xml

Last synced: 2 days ago
JSON representation

Bridges for api projects.

Awesome Lists containing this project

README

        

Api Bridge
==
Install:
```
composer require bigoen/api-bridge
```

SimpleClient
==
Create model:
```php
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();
```

JsonldClient
==
Create model:
```php
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();
```

Convert api values in tree. Details: https://github.com/bigoen/api-bridge-converter