You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* URL end point that begins at root (leading `/` is optional)
73
76
* URLs are allowed to have parameters defined denoted using a colon (`:`)
74
77
* Example: `users/:id`
75
-
***controller**
76
-
* The controller name is the prefix of the file it is defined in. For example you would use `users` for the controller `app/controllers/users_controller.js`
78
+
***controller** (optional)
79
+
* The controller name is the prefix of the file it is defined in. e.g. `users` for `app/controllers/users_controller.js`
80
+
* May be omitted to set the controller name to the first part of the route **url**. e.g. `users` for `['get users/all', 'getAll']`
77
81
***action**
78
-
* This is the name of the function to call defined in the controller.
82
+
* This is the name of the method to call defined in the controller.
83
+
***subroutes**
84
+
* Subroutes may be defined instead of a controller and action.
79
85
80
86
There are a couple ways to define how routes work:
81
87
82
-
1.All inline:
88
+
1.Inline:
83
89
84
90
```javascript
85
91
module.exports= [
86
92
['get users/all', 'users#getAll']
87
93
]
88
94
```
89
95
90
-
1.Nested:
96
+
1.With subroutes:
91
97
92
98
```javascript
93
99
module.exports= [
@@ -109,6 +115,33 @@ There are a couple ways to define how routes work:
109
115
]
110
116
```
111
117
118
+
1.[With `resources` verb](#resources):
119
+
120
+
```javascript
121
+
module.exports= [
122
+
['resources users']
123
+
]
124
+
```
125
+
126
+
#### Resources
127
+
128
+
Auto generate resource routes with the `['resources {name}']` route format.
129
+
130
+
The **name** of the resource must be a single word.
131
+
132
+
The following routes will be generated:
133
+
134
+
```javascript
135
+
[{name}, [
136
+
[`get /`, 'fetchAll'],
137
+
[`get /:id`, 'fetch'],
138
+
[`post /`, 'create'],
139
+
[`patch /:id`, 'update'],
140
+
[`put /:id`, 'replace'],
141
+
[`delete /:id`, 'destroy']
142
+
]]
143
+
```
144
+
112
145
### Controllers
113
146
114
147
Controllers are used to define the actions to take place on each request.
0 commit comments