In the world of web development, understanding HTTP methods is fundamental. Two of the most common HTTP methods you’ll encounter are GET and POST. In this blog post, we’ll dive into HTTP GET vs. POST and provide examples of sending GET and POST requests to a server on Windows and Linux.

1. GET vs. POST @ CRUD

HTTP methods, sometimes called “verbs”, dictate the type of action the request intends to perform. Refer to the mapping table between HTTP methods and CRUD to easily remember them. Below is the IBM’s explanation.

HTTP MethodsDescription
POSTCreates a resource.
GETRetrieves a resource.
PUTUpdates an existing resource. Do not create the resource if it does not exist.
DELETEDeletes a resource.
HTTP Methods mapped to CRUD

The above mapping can get complicated if we consider more details of HTTP methods. We’ll leave users to explore. Please refer to StackOverflow discussion, CURD vs. REST, and CRUD mapping to HTTP Verbs.

2. The GET Method

The GET method requests a representation of a specified resource. It should only retrieve data and should have no other side effects.

2.1 Characteristics of GET:

  • Idempotent: Making multiple identical GET requests should produce the same result every time.
  • Data in the URL: Data sent to the server is appended to the URL as query parameters.
  • URL Length Limitation: Because data is appended to the URL, there’s a limit to how much data can be sent. Most modern web browsers support 2K length of URL.
  • Bookmarkable: Since the data is part of the URL, GET requests can be bookmarked.

2.2 Send a GET request

2.2.1 Curl @ Linux

On Linux, you may use curl to send the request.


2.2.2 Browser Address Bar @ Windows

You may open your favorite web browser on Windows and type the URL in the address bar. Please note typing in a web browser address bars and pressing enter only results in GET request.

GET request through Chrome address bar
GET request using the address bar

3. The POST Method

The POST method submits data to be processed to a specified resource. It’s used when submitting form data or uploading a file.

3.1 Characteristics of POST:

  • Not Idempotent: Making identical POST requests may produce different results.
  • Data in the Body: Data sent to the server is in the request header or body. Although no specific header and body limits are defined in the HTTP standard, every web server has its implementation limit. As a rule of thumb, think of the header with a 4K limit and the body with a 2G (could be configured higher) limit.
  • No URL Length Limitation: Data isn’t appended to the URL so you can send larger amounts of data.
  • Not Bookmarkable: Since data is in the request body and not the URL, you can’t bookmark a POST request.

3.2 Send a POST request

3.2.1 Curl @ Linux

On Linux, you may use curl to send the request.

curl -X POST -H "Content-Type: application/json" -d '{"name":"John", "age":30}'

3.2.2 Postman @ Windows

You’ll need to install Postman on Windows to send a POST request.

Click the ‘+’ on the right side of your workspace.

postman workspace

Then, in the newly opened tab, select POST.

postman edit request

4. GET vs POST: When to use which?

  • Use GET when you’re only retrieving data, like fetching a blog post or querying a database.
  • Use POST when submitting data to be processed, like submitting a form, logging into a website, or uploading a file.

5. Conclusion

While GET and POST are the most commonly used HTTP methods, there are others like PUT, DELETE, PATCH, etc., each serving its purpose in the realm of web communication. Understanding the distinctions between each method is crucial for effective web development and ensuring that data is handled efficiently and securely. You are welcome to check more blogs about infrastructure.

[Credit: Featured image is proudly generated by Midjourney]

Leave a Reply

Your email address will not be published. Required fields are marked *