adonis-resource-controller

0.3.0 • Public • Published

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'])
  1. Install
    npm i -S adonis-resource-controller
  2. 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:

    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, },
        }
      }
     
    }
  2. Clone rest-admin

  3. 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/
  4. npm run dev

  5. Open http://localhost:8080/#/rest/users

Is that what you want? :)

Readme

Keywords

Package Sidebar

Install

npm i adonis-resource-controller

Weekly Downloads

3

Version

0.3.0

License

MIT

Unpacked Size

6.16 kB

Total Files

4

Last publish

Collaborators

  • wxs77577