DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

HTTP Methods Every Web Developer Must Know

Kristiono Setyadi user avatar by
Kristiono Setyadi
·
Aug. 19, 12 · Interview
Like (0)
Save
Tweet
Share
9.53K Views

Join the DZone community and get the full member experience.

Join For Free

I’ve been programming web for years and I saw a lot of so-called web programmers doing web programming in their own preferred language. Most of them I’ve known were using PHP while a small group of them use Ruby and Python. But the languages doesn’t make any differences when it comes to HTTP Method.

A few weeks ago, I’ve worked with someone who really has expertise in PHP and has doing PHP for 6 years, give or take. I really love working with him as his knowledge about PHP overtakes mine and I do love to learn from him. One thing that I missed about was when he was using the wrong method for particular HTTP requests. He used GET where he should used POST, recklessly using (again!) GET instead of DELETE. But when I asked him about whether he was understand in what he’s doing, he answered, “it works. From the first day I learn PHP, it still works.”

I don’t want to judge him and throw all the mistakes on everything he read but this is dangerous as he will, in the future, be working with a beginner programmer in pair-programming. He could mistakenly put the wrong concepts and mix things up between GET, POST, PUT and DELETE (and another not-so-famous method in HTTP).

Trying so hard to remember all HTTP methods (and all their purposes) is just as hard as writing “Hello World” in Java without using an IDE for beginners. If you’re a web veteran and can spell all HTTP methods without thinking then you should not wasting your time reading this. Go get your things done. To those who are still confused and don’t care before about those methods, go read ahead.

The Four (Plus One) Elements

Two of them are probably the most frequently used by you and two (plus one) of them are rarely use even though most of programmers are aware of their existence.

GET

“I get something!”

“Get the data and back off!”

As you might know, GET should always only getting the data from the specified resources and should not create any action other than retrieval. If you want to save the data to database, modify files, etc., do not use GET. This is important as GET (and HEAD, see below) is considered “safe”.

HEAD

We can say that this is the light version of GET because HEAD is actually the same as GET but ignoring the response body. When do we use HEAD instead of GET? Testing links, check for modifications, etc., that is for something that you didn’t need to read the response body and just okay with the response header.

POST

If GET retrieved the data then POST is a method to store data, create new resources, etc. POST to GET is like “write” to “read”. Pretty simple. (You might be wondering why I simplify things and not telling the truth about the vary responses, whether it’s 200, 201, or 204. If you’re really curious about those response codes, please refer to RFC2616: HTTP Status Code Definitions. ).

PUT

PUT, simply put, is practically the same with POST. The difference between PUT and POST is in its behavior. Read this explanation for a brief and easy-to-understand answer.

DELETE

As the name suggests, DELETE is the “opposite” of PUT. Again, DELETE to PUT is like “erase” to “write”. No big deal. (I know some people who use POST to delete or destroy the data/resource but that should not happened).

“So if PUT and DELETE are identical with POST, why we would do something using PUT and DELETE instead of POST?“, you asked.

PUT and DELETE is idempotency. I repeat, idempotency. No matter how much you use PUT or DELETE, if you do that more than one within the same resource, it will be counted as one. This rule is not applicable for POST as everytime you do the POST, the (same) data will be stored/created over and over again. Elliotte Rusty Harold explained about this in an interview six years ago.

There’s more than this. You can see another three methods: TRACE, CONNECT, and OPTIONS and the relatively new method: PATCH.

Web developer POST (HTTP)

Published at DZone with permission of Kristiono Setyadi. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • When AI Strengthens Good Old Chatbots: A Brief History of Conversational AI
  • Playwright vs. Cypress: The King Is Dead, Long Live the King?
  • Easy Smart Contract Debugging With Truffle’s Console.log
  • Secrets Management

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: