ash-framework / roadmap

0 stars 0 forks source link

Update cli route generator with --verbs option #35

Open digitalsadhu opened 7 years ago

digitalsadhu commented 7 years ago

Without --verbs

# ash generate route users

Would generate

Router.map(function () {
  this.route('users')
})

and

|- routes
  |- users.js

With --verbs

1.

# ash generate route users --verbs get,patch,post,delete

Would generate

Router.map(function () {
  this.route('users')
})
|- routes
  |- users.get.js
  |- users.patch.js
  |- users.post.js
  |- users.delete.js

2.

# ash generate route users/index --verbs post,delete

Would generate

Router.map(function () {
  this.route('users', function () { })
})

and

|- routes
  |- users
    |- index.post.js
    |- index.delete.js
digitalsadhu commented 7 years ago

@pnw This look right to you?

pnw commented 7 years ago
  1. If that route already exists, would I use the same command to add new verbs? Presumably Ash would be smart enough to recognize, you already have a get verb, so don't try to re-create it
  2. Do you expect to whitelist certain verbs, or do we just do a simple e.g. verbs = input.split(',') to get the list of desired verbs? Here is the closest thing I can find to a definitive list of official HTTP verbs plus some MS-invented ones. On second thought though, I suppose we just allow the verbs that express allows (assuming Ash is built on top of express)
  3. Nice to have: possibly add a shortcut --crud flag or shorthand, single-letter version of these verbs, like -cru for get,post,put or -crudoha for get,post,put,patch,delete,options,head
pnw commented 7 years ago

Re: whitelisted verbs, maybe the way to do it is like in the config.js,

ENV.verbs = ['get', 'post', 'put', 'delete', 'patch', 'option']

kind of thing. And the default value for that is all of the verbs that express allows out of the box. Looking into it a bit, it seems that express only allows a specific set of verbs defined by what the http module allows.