{"id":22640443,"url":"https://github.com/simialbi/yii2-rest-client","last_synced_at":"2025-04-11T22:10:59.637Z","repository":{"id":47450132,"uuid":"106551260","full_name":"simialbi/yii2-rest-client","owner":"simialbi","description":"REST client (AR-like model) for Yii Framework 2.0 (via yii2-http-client)","archived":false,"fork":false,"pushed_at":"2022-07-28T07:24:41.000Z","size":132,"stargazers_count":21,"open_issues_count":1,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-11T13:53:16.228Z","etag":null,"topics":["activerecord","client","model","rest","yii2"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simialbi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-11T12:28:00.000Z","updated_at":"2025-03-31T13:45:22.000Z","dependencies_parsed_at":"2022-09-22T14:41:16.786Z","dependency_job_id":null,"html_url":"https://github.com/simialbi/yii2-rest-client","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simialbi%2Fyii2-rest-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simialbi%2Fyii2-rest-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simialbi%2Fyii2-rest-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simialbi%2Fyii2-rest-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simialbi","download_url":"https://codeload.github.com/simialbi/yii2-rest-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248487695,"owners_count":21112191,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["activerecord","client","model","rest","yii2"],"created_at":"2024-12-09T04:10:27.430Z","updated_at":"2025-04-11T22:10:59.613Z","avatar_url":"https://github.com/simialbi.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# REST Client for Yii 2 (ActiveRecord-like model)\nThis extension provides an interface to work with RESTful API via ActiveRecord-like model in Yii 2.\nIt is based on [ApexWire's](https://github.com/ApexWire) [yii2-restclient](https://github.com/ApexWire/yii2-restclient).\n\n\n[![Latest Stable Version](https://poser.pugx.org/simialbi/yii2-rest-client/v/stable?format=flat-square)](https://packagist.org/packages/simialbi/yii2-rest-client)\n[![Total Downloads](https://poser.pugx.org/simialbi/yii2-rest-client/downloads?format=flat-square)](https://packagist.org/packages/simialbi/yii2-rest-client)\n[![License](https://poser.pugx.org/simialbi/yii2-rest-client/license?format=flat-square)](https://packagist.org/packages/simialbi/yii2-rest-client)\n![Build Status](https://github.com/simialbi/yii2-rest-client/workflows/build/badge.svg)\n\n## Resources\n * [yii2-restclient](https://github.com/ApexWire/yii2-restclient)\n * [\\yii\\db\\ActiveRecord](http://www.yiiframework.com/doc-2.0/guide-db-active-record.html)\n\n## Installation\nThe preferred way to install this extension is through [composer](http://getcomposer.org/download/).\n\nEither run\n\n```\n$ php composer.phar require --prefer-dist simialbi/yii2-rest-client\n```\n\nor add\n\n```\n\"simialbi/yii2-rest-client\": \"*\"\n```\n\nto the `require` section of your `composer.json`.\n\n## Configuration\nTo use this extension, configure restclient component in your application config:\n\n```php\n    'components' =\u003e [\n        'rest' =\u003e [\n            'class' =\u003e 'simialbi\\yii2\\rest\\Connection',\n            'baseUrl' =\u003e 'https://api.site.com/',\n            // 'auth' =\u003e function (simialbi\\yii2\\rest\\Connection $db) {\n            //      return 'Bearer: \u003cmytoken\u003e';\n            // },\n            // 'auth' =\u003e 'Bearer: \u003cmytoken\u003e',\n            // 'usePluralisation' =\u003e false,\n            // 'useFilterKeyword' =\u003e false,\n            // 'enableExceptions' =\u003e true,\n            // 'itemsProperty' =\u003e 'items'\n        ],\n    ],\n```\n\n| Parameter           | Default    | Description                                                                                                   |\n| ------------------- | -----------| ------------------------------------------------------------------------------------------------------------- |\n| `baseUrl`           | `''`       | The location of the api. E.g. for http://api.site.com/v1/users the `baseUrl` would be http://api.site.com/v1/  (required)   |\n| `auth`              |            | Either a Closure which returns a `string` or a `string`. The rest connection will be passed as parameter.        |\n| `usePluralisation`  | `true`     | Whether to use plural version for lists (index action) or not (e.g. http://api.site.com/users instead of `user`) |\n| `useFilterKeyword`  | `true`     | Whether to use \"filter\" key word in url parameters when filtering (e.g. ?filter[name]=user instead of ?name=user |\n| `enableExceptions`  | `false`    | Whether the connection should throw an exception if response is not 200 or not                                   |\n| `itemsProperty`     |            | If your items are wrapped inside a property (e.g. `items`), set it's name here                                   | \n| `requestConfig`     | `[]`       |  Client request configuration                                                                                    | \n| `responseConfig`    | `[]`       | Client response configuration                                                                                   | \n| `updateMethod`      | `'put'`    | The method to use for update operations.                                                                        | \n| `isTestMode`        | `false`    | Whether we are in test mode or not (prevent execution)                                                          | \n| `enableQueryCache`  | `false`    | Whether to enable query caching                                                                                 | \n| `queryCacheDuration`| `3600`     | The default number of seconds that query results can remain valid in cache                             | \n| `queryCache`        | `'cache'`  | The cache object or the ID of the cache application component                                           | \n\n## Usage\nDefine your Model\n\n```php\n\u003c?php\n\nnamespace app\\models;\n\nuse simialbi\\yii2\\rest\\ActiveRecord;\n\n/**\n * MyModel\n * \n * @property integer $id\n * @property string $name\n * @property string $description \n * \n * @property-read MyOtherModel $myOtherModel\n */\nclass MyModel extends ActiveRecord {\n    /**\n     * {@inheritdoc}\n     */\n    public static function modelName() {\n        return 'my-super-model-name';\n    }\n\n    /**\n     * {@inheritdoc}\n     */\n    public static function primaryKey() {\n        return ['id'];\n    }\n}\n\n/**\n * Class MyOtherModel\n * \n * @property integer $id\n * @property integer $my_model_id\n * @property string $subject\n * \n * @property-read MyModel[] $myModels\n */\nclass MyOtherModel extends ActiveRecord {\n    /**\n     * {@inheritdoc}\n     */\n    public static function primaryKey() {\n        return ['id'];\n    }\n}\n```\n\nIt's important that you define the primary key by overriding `primaryKey()` method. Otherwise you'll get an exception.\nIf you do not override the `modelName()` method, it will guess it by class name (**MyModel** becomes **my-model**). It's used\nto generate the URL together with `simialbi\\yii2\\rest\\Connection::$baseUrl`.\n\nThe usage how to define the active record (rules, behaviors etc.) is the same like [yii\\db\\ActiveRecord](http://www.yiiframework.com/doc-2.0/guide-db-active-record.html).\n\n\u003e Important: Be sure to either define the properties of the object like in the example above (`@property` syntax in phpdoc) \n\u003e or override the `attributes()` method to return the allowed attributes as array\n\n\u003e The same about relations. Be sure to either define them via `@property-read` phpdoc comment or override the `getRelations`\n\u003e method. If the related class has not the same namespace as the main class, be sure to use the fully qualified class name\n\u003e (e.g. `@property-read \\app\\models\\OtherModel[] $otherModels`)\n\n## License\n\n**yii2-rest-client** is released under MIT license. See bundled [LICENSE](LICENSE) for details.\n\n## Acknowledgments\n * [ApexWire's](https://github.com/ApexWire) [yii2-restclient](https://github.com/ApexWire/yii2-restclient)\n * [Yii2 HiArt](https://github.com/hiqdev/yii2-hiart).\n * [mikolajzieba](https://github.com/mikolajzieba)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimialbi%2Fyii2-rest-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimialbi%2Fyii2-rest-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimialbi%2Fyii2-rest-client/lists"}