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 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,162 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