Why Does PUT Work for Data Retrieval in My API, and Why Should I Use GET Instead?

Ratul Roy 20 Reputation points
2025-01-23T04:24:23.26+00:00

Detailed Question:

In my current API implementation, I’m using the PUT method to retrieve user profile data, and despite this being semantically incorrect, I am still able to successfully fetch the data. This leads me to wonder why it's necessary to use the GET method for data retrieval, especially since PUT seems to work for this purpose.

I understand that PUT is generally intended for updating or replacing resources, but given that my application is able to retrieve data via a PUT request without any issues (including generating the correct response codes), why is it technically better to use GET for this type of operation? What are the underlying technical reasons for using GET instead of PUT when retrieving data?

Furthermore, even though I'm using POST, PUT, and DELETE for operations like creating, updating, or deleting resources, none of these seem to interfere with the working of my APIs. The response codes generated (e.g., 200 OK, 201 Created, 204 No Content) are correct, and the data retrieval and manipulation seem to function fine. Why should we adhere to these distinct methods (GET for retrieval, POST for creation, PUT for updates, and DELETE for deletions) when the API works as expected without issues?

Context:

  • I am working with a backend API using ASP.NET Core, and the PUT method is currently handling profile data retrieval.
  • The frontend makes a PUT request with the user's JWT token to fetch user profile data.
  • Despite this non-standard usage, the data retrieval seems to work fine, and the correct HTTP response codes are returned.

Looking for:

  • An explanation of why using PUT for data retrieval is technically incorrect.
  • A breakdown of the best practices for using GET to fetch data in a RESTful API.
  • The potential implications of using PUT incorrectly (e.g., caching, client expectations, HTTP status codes, etc.).
  • Clarification on why we should use the distinct HTTP methods (GET, POST, PUT, DELETE) when the API functions correctly with these methods. Detailed Question: In my current API implementation, I’m using the PUT method to retrieve user profile data, and despite this being semantically incorrect, I am still able to successfully fetch the data. This leads me to wonder why it's necessary to use the GET method for data retrieval, especially since PUT seems to work for this purpose. I understand that PUT is generally intended for updating or replacing resources, but given that my application is able to retrieve data via a PUT request without any issues (including generating the correct response codes), why is it technically better to use GET for this type of operation? What are the underlying technical reasons for using GET instead of PUT when retrieving data? Furthermore, even though I'm using POST, PUT, and DELETE for operations like creating, updating, or deleting resources, none of these seem to interfere with the working of my APIs. The response codes generated (e.g., 200 OK, 201 Created, 204 No Content) are correct, and the data retrieval and manipulation seem to function fine. Why should we adhere to these distinct methods (GET for retrieval, POST for creation, PUT for updates, and DELETE for deletions) when the API works as expected without issues? Context:
    • I am working with a backend API using ASP.NET Core, and the PUT method is currently handling profile data retrieval.
    • The frontend makes a PUT request with the user's JWT token to fetch user profile data.
    • Despite this non-standard usage, the data retrieval seems to work fine, and the correct HTTP response codes are returned.
    Looking for:
    • An explanation of why using PUT for data retrieval is technically incorrect.
    • A breakdown of the best practices for using GET to fetch data in a RESTful API.
    • The potential implications of using PUT incorrectly (e.g., caching, client expectations, HTTP status codes, etc.).
    • Clarification on why we should use the distinct HTTP methods (GET, POST, PUT, DELETE) when the API functions correctly with these methods.
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,756 questions
ASP.NET API
ASP.NET API
ASP.NET: A set of technologies in the .NET Framework for building web applications and XML web services.API: A software intermediary that allows two applications to interact with each other.
367 questions
0 comments No comments
{count} votes

Accepted answer
  1. AgaveJoe 29,596 Reputation points
    2025-01-23T11:24:16.67+00:00

    An explanation of why using PUT for data retrieval is technically incorrect.

    Your are thinking about REST the wrong way.

    REST is architectural standard where the HTTP method defines the operation. GET is defined as a read only operation while PUT is a update.

    https://www.codecademy.com/article/what-is-rest

    Imagine if you are building a banking application where PUTs replace GETs. You'll have to be careful and septate the read-only PUT operations from the updates with code. Otherwise, a client could update a resource that should not be updated.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. SurferOnWww 3,811 Reputation points
    2025-01-23T12:24:27.5966667+00:00

    I’m using the PUT method to retrieve user profile data

    IMO, it is absolutely inappropriate. It sounds like "I am going my own way no matter how all the others in the world go the way that the world agrees".

    Please see the following document:

    CRUD (Create, Read, Update, Delete)


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.