Skip to content

REST client (AR-like model) for Yii Framework 2.0 (via yii2-http-client)

License

Notifications You must be signed in to change notification settings

mikolajzieba/yii2-rest-client

 
 

Repository files navigation

REST Client for Yii 2 (ActiveRecord-like model)

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

About

REST client (AR-like model) for Yii Framework 2.0 (via yii2-http-client)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%