Lesson 11
Review of Sails Blueprint REST Routes and Controller Actions
Summary
Summary of Transcript
In this lecture, the speaker provides a review of the routes offered by the Blueprint API, referring to a gist hosted on GitHub for reference. Here’s a breakdown of key points discussed:
Key Learning Points
-
Resources Overview:
- The API allows access to specific lists of resources which map to the
find
controller action. - Access to individual resources maps to the
findOne
controller action.
- The API allows access to specific lists of resources which map to the
-
Creating Resources:
- Use
POST /resource
to create a resource, which maps to thecreate
controller action. - The controller file will appear empty, yet actions are generated behind the scenes by the Blueprint API.
- Use
-
Updating Resources:
- Use
PUT
to update a resource, corresponding to theupdate
controller action.
- Use
-
Deleting Resources:
- Use
DELETE /resource/:id
to remove a resource, related to thedestroy
controller action.
- Use
-
Customizing Controller Actions:
- If customization is needed, you can explicitly define these actions in the controller file to override the default Blueprint API behavior.
- An example was provided on how to redefine the
create
action in the company controller.
Conclusion
The lecture concluded with an affirmation of the learned materials about Blueprint REST routes and controller actions, inviting viewers to continue their learning journey.
See you next time!
Video Transcript
Let's do a quick review about the routes it provides.
Going back to my gist here in git hub.
By the way, again, if you want to take a look at this gist, you can go to my gist profiles
nbkhope gist.github.com.nbkhope and you can click sales, blueprint, rest.
And here are the ones we learned.
We learned these guys here.
So we learned how to get a specific list of resources and that maps to the fine controller
action.
We learned how to get a specific resource and that maps to the fine one controller
action.
So we learned how to create a resource using pulse slash resource, which maps to the controller.createAction.
So these actions are all automatically generated by the blueprint API and you will not see them
written explicitly in the controller file.
The controller file is going to be empty as we can see if you go to API slash controller
slash company controller.
You can see there's nothing there, but actually there's something going on behind the scenes.
And for the to update a resource using put, you can which is mapped to the update controller
action.
Then finally we saw that you can also delete a resource at slash resource slash its ID
and it maps to the destroy controller action.
So these control actions are all provided by the blueprint API.
If you want to override them and change customize them, you can always do so just define these
actions in the controller file.
For example, just a brief example, if you would like to change the behavior of the controller
action.
So if you did a pulse slash resource and it's going to go to controller set dot create,
but you don't want it to go through the blueprint API.
So you can override that if you go to the editor and you can define here create in the
company control file, okay, and define your controller as so and that is going to automatically
override and it's going to use your definition instead of the behind the scenes definition.
Okay.
So just that.
So this is it.
That's it for this lecture.
We learned about the blueprint rest routes, the controller actions and see you next time.
Bye.
No comments yet (loading...)
No comments yet (loading...)
Did you like the lesson? 😆👍
Consider a donation to support our work: