Session 3: More Routes and Tools
Verb
Users Route
Purpose
Method name
GET
/users
Return multiple users
index
GET
/users/:userId
Return a single user
show
POST
/users
Create a user
create
PUT / PATCH
/users/:userId
Update a user
update
DELETE
/users/:userId
Delete a user (Soft Delete or Hard Delete based on code)
delete
Using the route() notation, all events with the same URI pattern are in the same line. Below, we've added routes for creating a new user, retrieving a single user, updating a user and deleting a user.
The notation /:userId indicates that that portion of the URI locator should be treated like a variable and added to the rc scope. For example /users/57 would fire the show handler and rc.userid would be 57.
route("/users/:userId").withAction({GET:"show",PUT:"update",DELETE:"delete"}).toHandler("Users");
route("/users").withAction({GET:"index",POST:"create"}).toHandler("Users");Last updated