{"id":16314773,"url":"https://github.com/forecho/yii2-rest-api","last_synced_at":"2025-03-16T14:30:51.190Z","repository":{"id":37525125,"uuid":"280352977","full_name":"forecho/yii2-rest-api","owner":"forecho","description":"Yii 2 REST API Project Template","archived":false,"fork":false,"pushed_at":"2023-04-19T20:51:27.000Z","size":224,"stargazers_count":40,"open_issues_count":3,"forks_count":14,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-27T10:35:19.106Z","etag":null,"topics":["yii2","yii2-template"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/forecho.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"open_collective":"yiier","custom":["https://blog-1251237404.cos.ap-guangzhou.myqcloud.com/20190424153510.png","https://blog-1251237404.cos.ap-guangzhou.myqcloud.com/20190424153431.png"]}},"created_at":"2020-07-17T07:08:05.000Z","updated_at":"2024-06-21T08:10:52.000Z","dependencies_parsed_at":"2024-10-27T10:53:58.806Z","dependency_job_id":"596323e5-5e2e-4f46-850e-bae8aab6f091","html_url":"https://github.com/forecho/yii2-rest-api","commit_stats":{"total_commits":54,"total_committers":2,"mean_commits":27.0,"dds":0.03703703703703709,"last_synced_commit":"35b3241ff654a8a0fb12736364450216b2738f89"},"previous_names":[],"tags_count":6,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/forecho%2Fyii2-rest-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/forecho%2Fyii2-rest-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/forecho%2Fyii2-rest-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/forecho%2Fyii2-rest-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/forecho","download_url":"https://codeload.github.com/forecho/yii2-rest-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243882236,"owners_count":20363109,"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":["yii2","yii2-template"],"created_at":"2024-10-10T21:55:14.742Z","updated_at":"2025-03-16T14:30:50.712Z","avatar_url":"https://github.com/forecho.png","language":"PHP","funding_links":["https://opencollective.com/yiier","https://blog-1251237404.cos.ap-guangzhou.myqcloud.com/20190424153510.png","https://blog-1251237404.cos.ap-guangzhou.myqcloud.com/20190424153431.png"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/yiisoft\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://avatars0.githubusercontent.com/u/993323\" height=\"100px\"\u003e\n    \u003c/a\u003e\n    \u003ch1 align=\"center\"\u003eYii 2 REST API Project Template\u003c/h1\u003e\n    \u003cbr\u003e\n\u003c/p\u003e\n\nYii 2 REST API Project Template is a skeleton [Yii 2](http://www.yiiframework.com/) application best for\nrapidly creating small rest api projects.\n\nThe template contains the basic features including user join/login api.\nIt includes all commonly used configurations that would allow you to focus on adding new\nfeatures to your application.\n\n[![Testing](https://github.com/forecho/yii2-rest-api/workflows/Testing/badge.svg)](https://github.com/forecho/yii2-rest-api/actions)\n[![Lint](https://github.com/forecho/yii2-rest-api/workflows/Lint/badge.svg)](https://github.com/forecho/yii2-rest-api/actions)\n[![Code Coverage](https://scrutinizer-ci.com/g/forecho/yii2-rest-api/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/forecho/yii2-rest-api/?branch=master)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/forecho/yii2-rest-api/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/forecho/yii2-rest-api/?branch=master)\n[![Latest Stable Version](https://poser.pugx.org/forecho/yii2-rest-api/v/stable)](https://packagist.org/packages/forecho/yii2-rest-api) \n[![Total Downloads](https://poser.pugx.org/forecho/yii2-rest-api/downloads)](https://packagist.org/packages/forecho/yii2-rest-api) \n[![Latest Unstable Version](https://poser.pugx.org/forecho/yii2-rest-api/v/unstable)](https://packagist.org/packages/forecho/yii2-rest-api) \n[![License](https://poser.pugx.org/forecho/yii2-rest-api/license)](https://packagist.org/packages/forecho/yii2-rest-api)\n\nREQUIREMENTS\n------------\n\nThe minimum requirement by this project template that your Web server supports PHP 7.2.0.\n\nINSTALLATION\n------------\n\n### Install via Composer\n\nIf you do not have [Composer](http://getcomposer.org/), you may install it by following the instructions\nat [getcomposer.org](http://getcomposer.org/doc/00-intro.md#installation-nix).\n\nYou can then install this project template using the following command:\n\n~~~\ncomposer create-project --prefer-dist forecho/yii2-rest-api \u003crest-api\u003e\ncd \u003crest-api\u003e\ncp .env.example .env\nphp yii generate/key # optional \nchmod 777 -R runtime/\n~~~\n\nNow you should be able to access the application through the following URL, assuming `rest-api` is the directory\ndirectly under the Web root.\n\n~~~\nhttp://localhost/\u003crest-api\u003e/web/\n~~~\n\n### Install from GitHub\n\nAccessing [Use this template](https://github.com/forecho/yii2-rest-api/generate) Create a new repository from yii2-rest-api\n\n```sh\ngit clone xxxx\ncd \u003crest-api\u003e\ncp .env.example .env\nchmod 777 -R runtime/\n```\n\nYou can then access the application through the following URL:\n\n~~~\nhttp://localhost/\u003crest-api\u003e/web/\n~~~\n\n\n### Install with Docker\n\nUpdate your vendor packages\n\n```sh\ndocker-compose run --rm php composer update --prefer-dist\n```\n\nRun the installation triggers (creating cookie validation code)\n\n```sh\ndocker-compose run --rm php composer install    \n```\n\nStart the container\n\n```sh\ndocker-compose up -d\n```\n   \nYou can then access the application through the following URL:\n\n```\nhttp://127.0.0.1:8000\n```\n\n**NOTES:** \n- Minimum required Docker engine version `17.04` for development (see [Performance tuning for volume mounts](https://docs.docker.com/docker-for-mac/osxfs-caching/))\n- The default configuration uses a host-volume in your home directory `.docker-composer` for composer caches\n\nCheck out the packages\n------------\n\n- [yiithings/yii2-doten](https://github.com/yiithings/yii2-doten)\n- [sizeg/yii2-jwt](https://github.com/sizeg/yii2-jwt)\n- [yiier/yii2-helpers](https://github.com/yiier/yii2-helpers)\n\nUse\n------------\n\nAt this time, you have a RESTful API server running at `http://127.0.0.1:8000`. It provides the following endpoints:\n\n* `GET /health-check`: a health check service provided for health checking purpose (needed when implementing a server cluster)\n* `POST /v1/join`: create a user\n* `POST /v1/login`: authenticates a user and generates a JWT\n* `POST /v1/refresh-token`: refresh a JWT\n\nTry the URL `http://localhost:8000/health-check` in a browser, and you should see something like `{\"code\":0,\"data\":\"OK\",\"message\":\"成功\"}` displayed.\n\nIf you have `cURL` or some API client tools (e.g. [Postman](https://www.getpostman.com/)), you may try the following \nmore complex scenarios:\n\n```shell\n# create a user via: POST /v1/join\ncurl -X POST -H \"Content-Type: application/json\" -d '{\"username\":\"demo\",\"email\":\"demo@email.com\",\"password\":\"pass123\"}' http://localhost:8000/v1/join\n# should return like: {\"code\":0,\"data\":{\"username\":\"demo\",\"email\":\"demo@email.com\",\"status\":1,\"created_at\":\"2020-07-18T16:38:11+08:00\",\"updated_at\":\"2020-07-18T16:38:11+08:00\",\"id\":17},\"message\":\"成功\"}\n\n# authenticate the user via: POST /v1/login\ncurl -X POST -H \"Content-Type: application/json\" -d '{\"username\": \"demo\", \"password\": \"pass123\"}' http://localhost:8000/v1/login\n# should return like: {\"code\":0,\"data\":{\"user\":{\"id\":4,\"username\":\"dem211o1\",\"avatar\":\"\",\"email\":\"de21mo1@mail.com\",\"status\":1,\"created_at\":\"2020-07-17T23:49:39+08:00\",\"updated_at\":\"2020-07-17T23:49:39+08:00\"},\"token\":\"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImp0aSI6IllpaS1SRVNULUFQSSJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3QiLCJqdGkiOiJZaWktUkVTVC1BUEkiLCJpYXQiOjE1OTUwNjQ5NzIsImV4cCI6MTU5NTMyNDE3MiwidXNlcm5hbWUiOiJkZW0yMTFvMSIsImlkIjo0fQ.y2NSVQe-TQ08RnXnF-o55h905G9WHo6GYHNaUWlKjDE\"},\"message\":\"成功\"}\n\n# refresh a JWT\ncurl -X POST -H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImp0aSI6IllpaS1SRVNULUFQSSJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3QiLCJqdGkiOiJZaWktUkVTVC1BUEkiLCJpYXQiOjE1OTUwNjQ5NzIsImV4cCI6MTU5NTMyNDE3MiwidXNlcm5hbWUiOiJkZW0yMTFvMSIsImlkIjo0fQ.y2NSVQe-TQ08RnXnF-o55h905G9WHo6GYHNaUWlKjDE' http://localhost:8000/v1/refresh-token\n# should return like: {\"code\":0,\"data\":{\"user\":{\"id\":4,\"username\":\"dem211o1\",\"avatar\":\"\",\"email\":\"de21mo1@mail.com\",\"status\":1,\"created_at\":\"2020-07-17T23:49:39+08:00\",\"updated_at\":\"2020-07-17T23:49:39+08:00\"},\"token\":\"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImp0aSI6IllpaS1SRVNULUFQSSJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3QiLCJqdGkiOiJZaWktUkVTVC1BUEkiLCJpYXQiOjE1OTUwNjQ5NzIsImV4cCI6MTU5NTMyNDE3MiwidXNlcm5hbWUiOiJkZW0yMTFvMSIsImlkIjo0fQ.y2NSVQe-TQ08RnXnF-o55h905G9WHo6GYHNaUWlKjDE\"},\"message\":\"成功\"}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fforecho%2Fyii2-rest-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fforecho%2Fyii2-rest-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fforecho%2Fyii2-rest-api/lists"}