What is the Intent of users.create route?


#1

When using Route.resources(), this:

Route.resource('users', 'UserController')

Eequates to this

Route.get('users', 'UserController.index').as('users.index')
Route.post('users', 'UserController.store').as('users.store')
Route.get('users/create', 'UserController.create').as('users.create')
Route.get('users/:id', 'UserController.show').as('users.show')
Route.put('users/:id', 'UserController.update').as('users.update')
Route.patch('users/:id', 'UserController.update')
Route.get('users/:id/edit', 'UserController.edit').as('users.edit')
Route.delete('users/:id', 'UserController.destroy').as('users.destroy')

What is that users.create route supposed to do?

Thank you,
Billal Begueradj


#2

It returns the view which helps you to create users… the register form i would say…
As far as I know users.index returns users collection and users.store post request stores users in db…
Let me know if that is correct


#3

Hey @begueradj! :wave:

This route intend to send back the view related to the creation of the user. Same goes for users.edit that should display the form to update a user.

If you are building an API, those routes are useless, therefore you can use the apiOnly() modifier to remove them.

Route.resource('users', 'UserController').apiOnly()

Doc: https://adonisjs.com/docs/4.1/routing#_apionly


#4

Yes… that’s what I mentioned. But what is the exact purpose of using apionly() ? I can do that just by returning json instead ?


#5

Excuse me if I’m wrong… For even creating and updating we can list the collection and single data to show them to make sure they’re editing the right one… so that it makes sense to have that route as well?


#6

apiOnly Removes GET resource/create and GET resource/:id/edit routes. That is mentioned here: https://adonisjs.com/docs/4.1/routing#_route_resources @Karthick-Ramachandra