adonis-resource-controller
v0.3.0
Published
Restful resource controller for AdonisJs
Downloads
26
Readme
adonis-resource-controller
Restful resource controller for AdonisJs
Usage
- 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'])
- Install
npm i -S adonis-resource-controller
- 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 onvue2
+bootstrap4
Usage
Let's getting start with CRUD for users.
Open your
/app/Models/User.js
, add afields()
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, }, } } }
Clone rest-admin
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/
npm run dev
Open http://localhost:8080/#/rest/users
Is that what you want? :)