Refresher: HTTP Verbs and Definitions
Embarrassingly enough, in a recent interview I was asked to list the HTTP Verbs and what they did and I blanked. I don’t know if it was the interview nerves, or if I was getting fatigued from rapid fire questions, or what — but I want to make sure that I gave myself a refresher on HTTP verbs, their paths, controller actions, and what they are used for. This blog post is mostly so I can forgive myself for being a huge dingus over forgetting them, but I hope it helps you as well.
There are nine main HTTP request methods, but for this blog I want to focus on the five that I had most commonly used. When I break down a verb, I will include the specific path that you would see in a URL (using the example of pets) well as the controller action used in conjunction with those verbs. The five verbs I use most are:
GET, POST, PATCH, PUT, DELETE
And the four that I do not use often are:
HEAD, CONNECT, OPTIONS, TRACE
GET
Use: request (and only request) data. Display a list of all pets
Controller Action: index
Path: /pets
POST
Use: create a new pet by sending data
Controller Action: create
Path: redirect from /pets/new to /pets
PATCH
Use: update parts of a specific pet
Controller Action: update
Path: redirect from /pets/:id/edit to /pet/:id
PUT
Use: similar to patch, but replaces the entire target of the request
Controller Action: update
Path: redirect from /pets/:id/edit to /pet/:id
DELETE
Use: delete a specific pet
Controller Action: destroy
Path: /students/:id
This refresher definitely helped remind me of some of the other topics that might have slipped my mind in the last few months since I originally learned them, I hope it was a refresher for you as well!
Resources:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
https://guides.rubyonrails.org/action_controller_overview.html