Resourceful Routes
Resourceful routes are convention based to help you create routing with less boilerplate.
In ColdBox, you can register resourceful routes (resources()
) to provide automatic mappings between HTTP verbs and URLs to event handlers and actions by convention. By convention, all resources map to a handler with the same name or they can be customized if needed. This allows for a standardized convention when building routed applications and less typing 😉
This single resource declaration will create all the necessary variations of URL patterns and HTTP Verbs to actions to handle the resource. Please see the table below with all the permutations it will create for you.
Verb | Route | Event | Purpose |
---|---|---|---|
GET |
| photos.index | Get all photos |
GET |
| photos.new | Return the HTML form for creating a photo |
POST |
| photos.create | Create a photo |
GET |
| photos.show | Show a photo by |
GET |
| photos.edit | Return the HTML form for editing the photo |
PUT/PATCH |
| photos.update | Update a photo by |
DELETE |
| photos.delete | Delete a photo by |
For in-depth usage of the resources()
method, let's investigate the API Signature:
Scaffolding Resources
We have created a scaffolding command in CommandBox to help you register and generate resourceful routes. Just run the following command in CommandBox to get all the help you will need in generating resources:
API Resourceful Routes
If you are building mostly API routes and not full HTML app routes, you can use the shortcut method apiResources()
method instead. This method will work the same as above BUT it will exclude the new
and edit
actions for you since we are in API Land.
Verb | Route | Event | Purpose |
---|---|---|---|
GET |
| photos.index | Get all photos |
POST |
| photos.create | Create a photo |
GET |
| photos.show | Show a photo by |
PUT/PATCH |
| photos.update | Update a photo by |
DELETE |
| photos.delete | Delete a photo by |
Last updated