PUT And PATCH Request In API

Introduction

  • APIs employs various HTTP methods but PUT, and PATCH are likely the two that cause the most confusion.
  • The resources can be updated or modified using either one of them.

Let's discuss how these approaches differ from one another.

PUT

The PUT method offers a technique to edit resources by delivering data that updates the entire resource.

PUT will completely swap out a resource if it already exists and creates the resource if it doesn't exist.

Imagine you wish to update the user using an API. We transmit all of the resource's attributes along with the PUT request.

PUT API request consumes more bandwidth than PATCH because we send all of the resource's contents using it.

PUT Request payload{
    "email":"[email protected]",
    "firstname":"qwerty",
    "lastname":"test",
    "pipeline_url":"https://test.com/pipeline"
}

PATCH

  • It's an alternate technique for upgrading resources.
  • In this instance, the client provides a portion of the modified data rather than changing the complete resource.
  • Fields that are not part of the payload won't be updated.

We're sending an email and a pipeline_url.

PATCH Request payload{
    "email":"[email protected]",
    "pipeline_url":"https://test.com/pipeline"
}

PATCH consumes less bandwidth than PUT because we only send information that needs to be updated.