simialbi/yii2-rest-client

REST client (AR-like model) for Yii Framework 2.0 (via yii2-http-client, extends ApexWire/yii2-restclient)

1.0.3 2017-10-16 16:06 UTC

README

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.

Resources

Installation

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.

Configuration

To use this extension, configure restclient component in your application config:

    'components' => [
        'rest' => [
            'class'   => 'simialbi\yii2\rest\Connection',
            'baseUrl' => 'https://api.site.com/'
        ],
    ],

Usage

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

License

yii2-rest-client is released under MIT license. See bundled LICENSE for details.

Acknowledgments