Question 1
Choose 1
What HTTP method in a RESTful web service is typically used to completely replace an existing resource?
Correct answer:
C. PUT
Explanation:
✅ Correct Option:
C. PUT
The PUT method is defined by the HTTP specification as idempotent and is used to replace the state of a resource at a known URI with the state defined in the request payload. If a resource exists at that URI, PUT completely overwrites it. If it does not exist, it is often created. This makes it the standard method for a complete update or replacement of an existing resource in RESTful design.
❌ Incorrect Options:
A. GET
The GET method is used solely for retrieving a representation of a resource. It is a safe, read-only operation that must not change the state of the resource on the server, making it unsuitable for any update or replace operation.
B. PATCH
The PATCH method is used for partial updates, not complete replacements. It applies a set of changes described in the request payload to the resource, modifying only the fields that are provided. It is not designed to replace the entire resource.
D. POST
The POST method is a general-purpose operation primarily used to create new resources within a collection. Its behavior is not standardized and is not idempotent. While it can sometimes be used for updates, it is not the standard or recommended method for a complete idempotent replacement of an existing resource.
📋 Summary:
In RESTful API design, HTTP methods have specific semantic meanings. The requirement is to completely replace an existing resource. The PUT method is explicitly designed for this purpose, as it is idempotent and instructs the server to store the enclosed payload at the supplied URI, fully replacing any existing resource there.
🔗 Reference:
RFC 7231, Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content, Section 4.3.4 (PUT)
✅ Correct Option:
C. PUT
The PUT method is defined by the HTTP specification as idempotent and is used to replace the state of a resource at a known URI with the state defined in the request payload. If a resource exists at that URI, PUT completely overwrites it. If it does not exist, it is often created. This makes it the standard method for a complete update or replacement of an existing resource in RESTful design.
❌ Incorrect Options:
A. GET
The GET method is used solely for retrieving a representation of a resource. It is a safe, read-only operation that must not change the state of the resource on the server, making it unsuitable for any update or replace operation.
B. PATCH
The PATCH method is used for partial updates, not complete replacements. It applies a set of changes described in the request payload to the resource, modifying only the fields that are provided. It is not designed to replace the entire resource.
D. POST
The POST method is a general-purpose operation primarily used to create new resources within a collection. Its behavior is not standardized and is not idempotent. While it can sometimes be used for updates, it is not the standard or recommended method for a complete idempotent replacement of an existing resource.
📋 Summary:
In RESTful API design, HTTP methods have specific semantic meanings. The requirement is to completely replace an existing resource. The PUT method is explicitly designed for this purpose, as it is idempotent and instructs the server to store the enclosed payload at the supplied URI, fully replacing any existing resource there.
🔗 Reference:
RFC 7231, Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content, Section 4.3.4 (PUT)
