PHPackages                             hiqdev/yii2-hiart - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. hiqdev/yii2-hiart

ActiveYii2-extension[HTTP &amp; Networking](/categories/http)

hiqdev/yii2-hiart
=================

ActiveRecord for API

0.4.0(7y ago)5951.8k↓40.5%15[1 issues](https://github.com/hiqdev/yii2-hiart/issues)[1 PRs](https://github.com/hiqdev/yii2-hiart/pulls)3BSD-3-ClausePHP

Since Aug 26Pushed 3mo ago13 watchersCompare

[ Source](https://github.com/hiqdev/yii2-hiart)[ Packagist](https://packagist.org/packages/hiqdev/yii2-hiart)[ Docs](https://github.com/hiqdev/yii2-hiart)[ RSS](/packages/hiqdev-yii2-hiart/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (15)Used By (3)

HiArt
=====

[](#hiart)

**ActiveRecord for API**

[![Latest Stable Version](https://camo.githubusercontent.com/3c6d124baa9da843fbc2cd5ad7d844399b997480be24d139dfeffb25a9f063bd/68747470733a2f2f706f7365722e707567782e6f72672f6869716465762f796969322d68696172742f762f737461626c65)](https://packagist.org/packages/hiqdev/yii2-hiart)[![Total Downloads](https://camo.githubusercontent.com/eeb3d0e63fc1eecda04943157bb4f0bf7a3df6b0425a5f3ebfb22b4e1c35346b/68747470733a2f2f706f7365722e707567782e6f72672f6869716465762f796969322d68696172742f646f776e6c6f616473)](https://packagist.org/packages/hiqdev/yii2-hiart)[![Build Status](https://camo.githubusercontent.com/0a089627c48009734e95888df2ac5caaa2d13bfa8a749efe7c2e1e53dc2f91af/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6869716465762f796969322d68696172742e737667)](https://travis-ci.org/hiqdev/yii2-hiart)[![Scrutinizer Code Coverage](https://camo.githubusercontent.com/77e80025bd72430fde3a73c479db293893777be72e33103c860be518a33722b2/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6869716465762f796969322d68696172742e737667)](https://scrutinizer-ci.com/g/hiqdev/yii2-hiart/)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/39cef62cfd816c04a7527e745d721a09053a84bc037d56d31face063763c6283/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6869716465762f796969322d68696172742e737667)](https://scrutinizer-ci.com/g/hiqdev/yii2-hiart/)[![Dependency Status](https://camo.githubusercontent.com/fa6ff91f9153f10cf6c6c254dd2791dfd864a0d2851332776ff26f3c4083387a/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f7068702f6869716465763a796969322d68696172742f6465762d6d61737465722f62616467652e737667)](https://www.versioneye.com/php/hiqdev:yii2-hiart/dev-master)

This Yii2 extension provides [ActiveRecord](http://en.wikipedia.org/wiki/Active_record_pattern)implementation that allows to access remote/web API same way as you do with normal [Yii2 DB ActiveRecord](http://www.yiiframework.com/doc-2.0/guide-db-active-record.html).

Installation
------------

[](#installation)

The preferred way to install this yii2-extension is through [composer](http://getcomposer.org/download/).

```
composer require "hiqdev/yii2-hiart"
```

But if you prefer [Guzzle](https://github.com/guzzle/guzzle) transport use `yii2-hiart-guzzle` package:

```
composer require "hiqdev/yii2-hiart-guzzle"
```

Configuration
-------------

[](#configuration)

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

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

Note three main options:

- `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

[](#transports)

Available transports are:

- **auto** - autodetects best supported transport
- [PHP streams](http://php.net/manual/en/book.stream.php), the most generic fallback, included in this package
- [cURL](http://php.net/manual/en/book.curl.php), included in this package
- [Guzzle](https://github.com/guzzle/guzzle), provided with [yii2-hiart-guzzle](https://github.com/hiqdev/yii2-hiart-guzzle)
- [yii2-httpclient](https://github.com/yiisoft/yii2-httpclient), provided with [yii2-hiart-httpclient](https://github.com/hiqdev/yii2-hiart-httpclient)

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.

### Query builders

[](#query-builders)

QueryBuilder is what actually implements an API.

We are developing `QueryBuilder`s for:

- Basic [REST API](https://en.wikipedia.org/wiki/Representational_state_transfer), included in this package
- [GitHub API](https://developer.github.com/v3/), provided with [yii2-hiart-github](https://github.com/hiqdev/yii2-hiart-github)
- [HiPanel API](https://hipanel.com/), provided with [hipanel-hiart](https://github.com/hiqdev/hipanel-hiart)

You can implement your own API. Basically all you need is create your `QueryBuilder` class with these methods:

- `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.

Usage
-----

[](#usage)

Define your Model:

```
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.

Then you just use your models same way as DB ActiveRecord models.

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

$user->save();

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

Basically all the features of [Yii2 ActiveRecord](http://www.yiiframework.com/doc-2.0/guide-db-active-record.html) work if your API provides them.

License
-------

[](#license)

This project is released under the terms of the BSD-3-Clause [license](LICENSE). Read more [here](http://choosealicense.com/licenses/bsd-3-clause).

Copyright © 2015-2018, HiQDev ()

Acknowledgments
---------------

[](#acknowledgments)

- This project was started as fork from [Yii2 Elasticsearch](https://github.com/yiisoft/yii2-elasticsearch).

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance55

Moderate activity, may be stable

Popularity42

Moderate usage in the ecosystem

Community27

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 56.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~115 days

Recently: every ~169 days

Total

12

Last Release

2644d ago

Major Versions

0.2.0 → 2.1.x-dev2018-04-04

0.3.0 → 3.0.x-dev2018-07-12

### Community

Maintainers

![](https://www.gravatar.com/avatar/790fd24da129907d373559f60c6994f664f06e3f518502c03580cc9f3594615e?d=identicon)[hiqdev](/maintainers/hiqdev)

---

Top Contributors

[![hiqsol](https://avatars.githubusercontent.com/u/11820365?v=4)](https://github.com/hiqsol "hiqsol (221 commits)")[![SilverFire](https://avatars.githubusercontent.com/u/4499203?v=4)](https://github.com/SilverFire "SilverFire (111 commits)")[![tafid](https://avatars.githubusercontent.com/u/3338188?v=4)](https://github.com/tafid "tafid (50 commits)")[![strorch](https://avatars.githubusercontent.com/u/23340907?v=4)](https://github.com/strorch "strorch (2 commits)")[![VadymHrechukha](https://avatars.githubusercontent.com/u/114911409?v=4)](https://github.com/VadymHrechukha "VadymHrechukha (2 commits)")[![bscheshirwork](https://avatars.githubusercontent.com/u/5769211?v=4)](https://github.com/bscheshirwork "bscheshirwork (2 commits)")[![InAdavansP](https://avatars.githubusercontent.com/u/22193236?v=4)](https://github.com/InAdavansP "InAdavansP (1 commits)")[![gadezist](https://avatars.githubusercontent.com/u/39760138?v=4)](https://github.com/gadezist "gadezist (1 commits)")[![bladeroot](https://avatars.githubusercontent.com/u/10207103?v=4)](https://github.com/bladeroot "bladeroot (1 commits)")

---

Tags

hacktoberfestapirestyii2extensionactiverecord

### Embed Badge

![Health badge](/badges/hiqdev-yii2-hiart/health.svg)

```
[![Health](https://phpackages.com/badges/hiqdev-yii2-hiart/health.svg)](https://phpackages.com/packages/hiqdev-yii2-hiart)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
