r/Web_Development • u/evilbooty • Dec 29 '20
When should I use different HTTP methods?
I've been building an ebay-style website for the past few months. Up until now I've only been using GET and POST requests. I'm aware of the other methods like PUT, PATCH, DELETE, etc. but I haven't seen any real reason to actually use them. I currently use POST requests to update, delete, and add database records; GET requests to open pages and pull data. Besides read-ability for my code, is there a reason I should be using these other methods that I'm overlooking?
1
Upvotes
7
u/hstarnaud Dec 29 '20
ELI5
GET: read only, never change the state of things, NEVER
POST: create something if you are truly restful, if you want to be pragmatic use it for custom actions
PUT: updates
DELETE: I cannot possibly see how you could misuse delete
2
u/ryan_holton Dec 29 '20
POST - for things like account creation and login, GET - for getting data, like a list of products, PUT & PATCH - typically for updating data, DELETE - for deleting records.
7
u/[deleted] Dec 29 '20
[removed] — view removed comment