Question

Difficulty: MediumCharacteristics of REST-Based APIs (CRUD, HTTP Verbs, Data Formats)

An administrator creates a new syslog server destination entry using a REST API endpoint on a network controller. Shortly after, the administrator needs to modify only the port number parameter for this existing log server entry, while preserving all other existing attributes without re-submitting the full resource payload. Which HTTP request verb and body approach should be utilized to perform this specific modification?

  1. HTTP PATCH with a payload containing only the port number key-value pairAnswer
  2. B
    HTTP PUT with a payload containing only the port number key-value pair
  3. C
    HTTP POST with a payload containing only the port number key-value pair
  4. D
    HTTP GET with the updated port number passed as a URL query parameter

Answer

HTTP PATCH with a payload containing only the port number key-value pair
In REST-based API design, the HTTP PATCH method is used to perform partial updates on an existing resource. When sending a PATCH request, the body contains only the specific key-value pairs that need to be changed, leaving all unmentioned parameters in their current state on the server.

Step-by-Step Solution

1
Identify the CRUD operation required for modifying a specific subset of fields on an existing resource.
The requirement calls for a partial update rather than a full resource replacement or creation.
The scenario explicitly states that only the port number should be modified while preserving all other existing attributes without resending the entire configuration.
2
Map the partial update operation to the corresponding RESTful HTTP verb.
HTTP PATCH is selected because it applies updates only to the fields included in the request body.
HTTP PUT replaces the resource entirely (omitted fields are lost/reset), whereas HTTP PATCH applies incremental or partial changes.

Key Concept

HTTP PATCH vs. PUT operations in REST APIs
Rate this question