{"id":20511856,"url":"https://github.com/wxs77577/adonis-rest","last_synced_at":"2025-04-13T22:42:33.432Z","repository":{"id":57173620,"uuid":"94077034","full_name":"wxs77577/adonis-rest","owner":"wxs77577","description":"Restful api for AdonisJs","archived":false,"fork":false,"pushed_at":"2018-11-16T06:36:51.000Z","size":49,"stargazers_count":17,"open_issues_count":2,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-25T11:20:45.374Z","etag":null,"topics":["adonis-china","adonisjs","crud","nodejs","rest-api","restful-api"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wxs77577.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-12T09:10:37.000Z","updated_at":"2019-08-28T12:28:09.000Z","dependencies_parsed_at":"2022-08-24T13:31:09.775Z","dependency_job_id":null,"html_url":"https://github.com/wxs77577/adonis-rest","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wxs77577%2Fadonis-rest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wxs77577%2Fadonis-rest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wxs77577%2Fadonis-rest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wxs77577%2Fadonis-rest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wxs77577","download_url":"https://codeload.github.com/wxs77577/adonis-rest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248794565,"owners_count":21162613,"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":["adonis-china","adonisjs","crud","nodejs","rest-api","restful-api"],"created_at":"2024-11-15T20:38:16.363Z","updated_at":"2025-04-13T22:42:33.141Z","avatar_url":"https://github.com/wxs77577.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AdonisJs Restful API\n\n\u003e **Not ready for production**\n  Currently support [AdonisJs v4](https://adonisjs.com/)+[MongoDB](https://github.com/duyluonglc/lucid-mongo) only.\n  Also check [REST-ADMIN](https://github.com/wxs77577/rest-admin) - An awesome admin dashboard based on vue 2 and bootstrap v4\n\n## Setup\n\u003e also you can use `npm` by ommit `--yarn`\n\n1. Install required packages\n    ```bash\n    adonis install @adonisjs/validator --yarn\n    adonis install @adonisjs/antl --yarn\n    adonis install @adonisjs/drive --yarn\n    adonis install lucid-mongo --yarn\n\n    # install adonis-rest\n    adonis install adonis-rest --yarn\n    \n    ```\n1. Edit `/start/app.js`\n    \n    ```js\n    const providers = [\n      '@adonisjs/validator/providers/ValidatorProvider',\n      '@adonisjs/antl/providers/AntlProvider',\n      '@adonisjs/drive/providers/DriveProvider',\n      'lucid-mongo/providers/LucidMongoProvider',\n\n      'adonis-rest/providers/RestProvider',\n    ]\n    ```\n\n1. Edit `/start/routes.js`\n    ```js\n    `Route.rest('/rest/api', 'api')`\n    ```\n1. Open `http://localhost:3333/rest/api/users` (or another port) should return paginated user list.\n\n## Documentation \n\n### Config\nThe config file of `adonis-rest` is `/config/rest.js`,you can define any number of **modules** of adonis-rest routes. e.g. For **frontend api** and **backend api**, we call them `api` and `admin`\n```js\nmodule.exports = {\n  //route module name\n  api: {\n    //authenticator name\n    auth: 'jwt',\n\n    // which means there are only `index` and `show` routes\n    isAdmin: false,\n\n    //all of your resources config\n    resources: {\n      \n      // for `/products`\n      products: {\n        // must access with a valid token\n        auth: true,\n\n        // all of your default query config for `/products`\n        query: {\n\n          // when list all products\n          index: {\n            // fetch appends, please refer to **Appends**\n            append: ['is_buy'],\n\n            // fetch related data\n            with: ['categories'],\n\n            // also you can define default sorting\n            sort: { _id: -1 },\n          },\n\n          // when show a product\n          show: {\n            append: ['is_buy'],\n          }\n        }\n      },\n      \n    }\n  },\n  admin: {\n    //maybe `adminJwt`\n    auth: 'jwt',\n\n    //allow C(create)/U(update)D/(delete) routes\n    isAdmin: true,\n\n    //allow destroy all routes\n    allowDestroyAll: true,\n\n\n    resources: {\n      // ...\n    }\n  }\n}\n```\n\nAnd then, you can add routes easily:\n`/start/routes.js`\n```js\n/**\n * @param String base url\n * @param string key of route module in `/config/rest.js`\n **/\nRoute.rest('/rest/api', 'api')\nRoute.rest('/rest/admin', 'admin')\n```\nNow, You can check the followed links: (if your port of server is `3333`)\n\n- http://localhost:3333/rest/api/product\n- http://localhost:3333/rest/admin/products\n\n\n### Base Model\nThere is a more powerful base model `Rest/Models/Model`\n\nYou can define a `Product` model like this:\n\n```js\nconst Model = use('Rest/Models/Model')\n\nmodule.exports = class Product extends Model {\n\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwxs77577%2Fadonis-rest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwxs77577%2Fadonis-rest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwxs77577%2Fadonis-rest/lists"}