DEV Community

Cover image for HTTP  Request Methods  (aka HTTP Verbs)
Randy Steele
Randy Steele

Posted on

HTTP Request Methods (aka HTTP Verbs)

Hey guys, I wanted to review something that can be pretty confusing for newer software engineers/coders. The different HTTP Verbs, what they mean and what they do. First let's talk a little bit about what a http request method actually is. HTTP or Hypertext Transfer Protocol has defined a set of protocols or request methods to indicate a certain desired action for a given resource. Let's review some of those http verbs now.

GET - A get request is a request to the specified resource and it should always only retrieve data. An example get request could look like this; HTTParty.get('https://example.api.testlodge.com/v1/projects.json') This would return a string that contains the HTML content of the requested page. Admittedly, you probably don't want to return it that way because it will be messy and possibly useless but that is a simple get request in http.

POST - The post request is used to submit a new entity to the requested resource. An example post request could look like this HTTParty.post("http://example.com/login", body: { user: "demo@me.com", password: "my_password" })

PATCH - The patch request is used to edit a resource. An example patch request could look like this HTTParty.patch('www.me.com', body: { name: my_name, age: 100 })

DELETE - The delete request is pretty self explanatory, it is used to delete an entity from the specified resource. An example could look like this HTTParty.delete('https://me.com/v1/projects/1.json')

These are the four most commonly used http verbs, they are others that you can checkout here!

I think that as developers we can get used to things 'just working' and we don't always understand what's going on under the hood. So for example when we use the resources: movies in our ruby config/routes.rb file we just know that we have all of these routes created for us and it's very nice and helpful but sometimes it's good to just go back to the basics and write out these requests manually either for practice or just so you can better understand what is happening when you are creating these routes in your app.

Additional resources:
Ruby Guides
MDN

Top comments (0)