2017 © Pedro Peláez
 

yii2-extension yii2-hiart

ActiveRecord for API

image

hiqdev/yii2-hiart

ActiveRecord for API

  • Thursday, July 12, 2018
  • by hiqdev
  • Repository
  • 10 Watchers
  • 36 Stars
  • 8,038 Installations
  • PHP
  • 7 Dependents
  • 0 Suggesters
  • 11 Forks
  • 4 Open issues
  • 13 Versions
  • 9 % Grown

The README.md

HiArt

ActiveRecord for API, (*1)

Latest Stable Version Total Downloads Build Status Scrutinizer Code Coverage Scrutinizer Code Quality Dependency Status, (*2)

This Yii2 extension provides ActiveRecord implementation that allows to access remote/web API same way as you do with normal Yii2 DB ActiveRecord., (*3)

Installation

The preferred way to install this yii2-extension is through composer., (*4)

composer require "hiqdev/yii2-hiart"

But if you prefer Guzzle transport use yii2-hiart-guzzle package:, (*5)

composer require "hiqdev/yii2-hiart-guzzle"

Configuration

To use this extension, configure hiart component in your application config:, (*6)

    'components' => [
        'hiart' => [
            'class' => \hiqdev\hiart\rest\Connection::class,
            'requestClass' => \hiqdev\hiart\auto\Request::class,
            'baseUri' => 'https://site.com/api/v3/',
        ],
    ],

Note three main options:, (*7)

  • class specifies class that actually implements API to be accessed, REST in this case
  • requestClass specifies transport implementation to be used, auto in this case
  • baseUri specifies starting point of the API

Transports

Available transports are:, (*8)

You can implement your own transport. All you need is to create two classes: Request and Response, it's not difficult see available implementations. Transport can be even non-HTTP based., (*9)

Query builders

QueryBuilder is what actually implements an API., (*10)

We are developing QueryBuilders for:, (*11)

You can implement your own API. Basically all you need is create your QueryBuilder class with these methods:, (*12)

  • buildMethod(Query $query)
  • buildHeaders(Query $query)
  • buildUri(Query $query)
  • buildQueryParams(Query $query)
  • buildBody(Query $query)
  • buildFormParams(Query $query)

See available implementations and ask questions using issues on GitHub., (*13)

Usage

Define your Model:, (*14)

class User extends \hiqdev\hiart\ActiveRecord
{
    public function rules()
    {
        return [
            ['id', 'integer', 'min' => 1],
            ['login', 'string', 'min' => 2, 'max' => 32],
        ];
    }
}

Note that you use general hiqdev\hiart\ActiveRecord class not specific for certain API. API is specified in connection options and you don't need to change model classes when you change API., (*15)

Then you just use your models same way as DB ActiveRecord models., (*16)

$user = new User();
$user->login = 'sol';

$user->save();

$admins = User::find()->where(['type' => User::ADMIN_TYPE])->all();

Basically all the features of Yii2 ActiveRecord work if your API provides them., (*17)

License

This project is released under the terms of the BSD-3-Clause license. Read more here., (*18)

Copyright © 2015-2018, HiQDev (http://hiqdev.com/), (*19)

Acknowledgments

The Versions

12/07 2018
11/05 2016

0.0.4

0.0.4.0 https://github.com/hiqdev/yii2-hiart

Tools to use API as ActiveRecord for Yii2

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

api extension yii2 activerecord

11/05 2016

0.0.3

0.0.3.0 https://github.com/hiqdev/yii2-hiart

Tools to use API as ActiveRecord for Yii2

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

api extension yii2 activerecord

11/05 2016

0.0.2

0.0.2.0 https://github.com/hiqdev/yii2-hiart

Tools to use API as ActiveRecord for Yii2

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

api extension yii2 activerecord

26/08 2015

0.0.1

0.0.1.0 https://github.com/hiqdev/yii2-hiart

Tools to use API as ActiveRecord for Yii2

  Sources   Download

BSD-3-Clause

The Requires

 

api extension yii2 activerecord