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 Build a REST API With Express Building API Routes in Express Error Handling in Express

Andrew Young
PLUS
Andrew Young
Courses Plus Student 639 Points

Why use post and why not use get

Currently we use post for vote-up and down but since you're not passing any value and html form supports get function why don't use get why use post instead?

Is it for security problems or just we usually use this method since I can copy the exact same code with same function just change the app.post to app.get, and still working

1 Answer

Tom Geraghty
Tom Geraghty
24,174 Points

Because it's the right thing to do. We're learning, so we should probably learn the correct way to do things instead of learning ways that work but aren't technically correct.

If we comply with the spec then our apps will be better rated by Google, they won't break when the spec is changed (following SemVer), they will be predictable to others who wish to utilize/consume our API, using GET can put sensitive information in the URL header which is more exposed to snoops, etc etc etc.

A couple good resources for more info: https://medium.com/@suhas_chatekar/why-you-should-use-the-recommended-http-methods-in-your-rest-apis-981359828bf7 https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html