0.4.0 • Published 5 years ago

@dolu/adonis-resource-controller v0.4.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

adonis-resource-controller

Restful resource controller for AdonisJs

Usage

  1. Requirements Please install adonis-resource-middleware first, and setup the routes with resource middleware. After that, your /start/routes.js should looks like this:

    const Route = use('Route')
    
    Route.resource('/api/:resource', 'ResourceController').middleware(['resource'])
  2. Install

    npm i -S adonis-resource-controller
  3. Make a controller: /app/Controllers/Http/ResourceController.js

    const BaseController = require('adonis-resource-controller')
    
    module.exports = class ResourceController extends BaseController {
    
    }

Now, you can play CRUD with your APIs. All CRUD Routes.

for REST-ADMIN

The routes and returned data gave a first-class supporting for rest-admin - A Powerful Admin Dashboard based on vue2 + bootstrap4

Usage

Let's getting start with CRUD for users. 1. Open your /app/Models/User.js, add a fields() method:

```javascript
class User {
  static get fields() {
    return {
      _id: { label: 'ID' },
      username: { label: 'Username', cols: 3 },
      password: { label: 'Password', type: 'password', listable: false, cols: 3 },
      is_active: { label: 'Is Active', type: 'switch', cols: 3, editable: false },
      member_type: { label: 'Member Type', type: 'select', options: [
        { text: 'VIP', value: 1 },
        { text: 'GOLD', value: 2 },
      ] },
      intro: { label: 'Intro', type: 'html', cols: 6, listable: false, },
    }
  }

}
```
  1. Clone rest-admin
  2. Copy .env to .env.development.local, open it, and change the API URL to the AdonisJs server api url:
    VUE_APP_API_URL=http://localhost:3333/api/
  3. npm run dev
  4. Open http://localhost:8080/#/rest/users

Is that what you want? :)