Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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?