1. Go to this page and download the library: Download muffin/webservice 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/ */
muffin / webservice example snippets
'Datasources' => [
// Other db config here
'webservice' => [
'className' => \Muffin\Webservice\Datasource\Connection::class,
'service' => 'Articles',
// Any additional keys will be set as Driver's config.
],
],
namespace App\Webservice\Driver;
use Cake\Http\Client;
use Muffin\Webservice\Driver\AbstractDriver;
class Articles extends AbstractDriver
{
/**
* Initialize is used to easily extend the constructor.
*/
public function initialize(): void
{
$this->setClient(new Client([
'host' => 'example.com'
]));
}
}
namespace App\Webservice;
use Muffin\Webservice\Datasource\Query;
use Muffin\Webservice\Datasource\ResultSet;
use Muffin\Webservice\Webservice\Webservice;
class ArticlesWebservice extends Webservice
{
/**
* Executes a query with the read action using the Cake HTTP Client
*/
protected function _executeReadQuery(Query $query, array $options = [])
{
$response = $this->getDriver()->getClient()->get('/articles.json');
if (!$response->isOk()) {
return false;
}
$resources = $this->_transformResults($query->endpoint(), $response->json['articles']);
return new ResultSet($resources, count($resources));
}
}
namespace App\Model\Endpoint;
use Muffin\Webservice\Model\Endpoint;
class ArticlesEndpoint extends Endpoint
{
}
namespace App\Model\Resource;
use Muffin\Webservice\Model\Resource;
class Article extends Resource
{
}
namespace App\Controller;
use Muffin\Webservice\Model\EndpointLocator;
class ArticlesController extends AppController
{
// Either set the default model type to "Endpoint" or explicitly specify
// model type in loadModel() call as shown below.
protected $_modelType = 'Endpoint';
public function index()
{
// This is
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.