DEV Community

Discussion on: Explain HTTP Verbs like I'm Five

Collapse
 
jacoby profile image
Dave Jacoby • Edited

This should be easy to explain, but honestly, I never used anything but GET and POST until recently, because until AJAX and REST APIs came to the fore, it didn't make sense. I mean, you wouldn't want just anyone to modify or delete your pages, right?

GET is the most common one. You want a page/image/library/video/feed/whatever, it gets it. I don't know if this is RFC-specific or just part of Apache, but you can only use QUERY_STRING with this verb. This allows you have Next link to http://example.com/?page=2, which can (and did) easily get unmanageable as options grew.

POST in the old way allowed you to send the query without having an excessively large query string in the URL. In the post-REST world, the best way to think of POST is as the CREATE of CRUD interaction, as GET is READ.

DELETE is DELETE in CRUD. Whatever you're referencing, remove it, even if that's just setting a 'deleted' flag for the entry in the database entry.

And finally, PUT is the equivalent to CRUD's UPDATE, where it takes the input as changes.

The source I love for diving more deeply into creating REST APIs is Build APIs You Won't Hate by Phil Sturgeon. The example code on Github is Laravel-centric, but the text is not, which makes it easily adaptable to whatever environment you find yourself in.