This extension provides an interface to work with RESTful API via ActiveRecord-like model in Yii 2. It is based on ApexWire's yii2-restclient.
The preferred way to install this extension is through composer.
Either run
$ php composer.phar require --prefer-dist simialbi/yii2-rest-client
or add
"simialbi/yii2-rest-client": "*"
to the require
section of your composer.json
.
To use this extension, configure restclient component in your application config:
'components' => [
'rest' => [
'class' => 'simialbi\yii2\rest\Connection',
'baseUrl' => 'https://api.site.com/'
],
],
Define your Model
<?php
namespace app\models;
use simialbi\yii2\rest\ActiveRecord;
class MyModel extends ActiveRecord {
/**
* @inheritdoc
*/
public static function modelName() {
return 'my-super-model-name';
}
/**
* @inheritdoc
*/
public static function primaryKey() {
return ['id'];
}
}
The usage after define a model is the same like yii\db\ActiveRecord
yii2-rest-client is released under MIT license. See bundled LICENSE for details.