Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Ryan Wittrup
Ryan Wittrup
9,156 Points

Logic behind using router.param for both GET and POST

Maybe I'm missing something, but is there a specific reason to use the router.param method for handling both GET and POST requests?

The reason I ask is, this seems like an unnecessary API cal for the POST and could use up more resources than are needed. I believe handling the POST method this way means you are calling to the database to first GET the object to be updated, push the changes, then save back to the database. It seems like this makes every POST request do double work as a GET request first. Am I understanding this right?

This may not matter when you have a relatively small object or a small number of calls, but I imagine this kind of structure could be a problem at scale.

Wouldn't it make more sense to directly update the document rather than doing a find first?