DEV Community

Hemant Govekar
Hemant Govekar

Posted on

1 1

Explain PUT POST and PATCH

In HTTPS, the HTTP methods PUT, POST, and PATCH are used to perform operations on resources. Here's a differentiation of their purposes and behavior:

  1. POST:
  • Purpose: Used to create new resources or submit data to a server. It appends the resource to an existing collection.
  • Idempotency: Not idempotent; multiple identical POST requests will create multiple resources.
  • Example: Submitting a registration form to create a new user.
  • Response: Usually returns 201 Created and a URI pointing to the newly created resource.
  1. PUT:
  • Purpose: Used to create or completely replace a resource at a specific URI. If the resource exists, it is updated; if it doesn't, it is created.
  • Idempotency: Idempotent; multiple identical PUT requests will produce the same result (i.e., the same resource state).
  • Example: Updating an entire profile with a new set of data.
  • Response: Typically returns 200 OK (if updated) or 201 Created (if new resource is created).
  1. PATCH:
    • Purpose: Used to partially update an existing resource. Only the fields provided in the request will be updated, leaving the rest unchanged.
    • Idempotency: Idempotent; multiple identical PATCH requests will result in the same resource state.
    • Example: Updating just the email address of a user profile without altering other fields.
    • Response: Commonly returns 200 OK or 204 No Content.

Key Differences

Method Action Idempotency Typical Use Case
POST Create new resource No Submitting forms or adding records to a database
PUT Replace entire resource Yes Overwriting or creating a resource at a specific URI
PATCH Update part of a resource Yes Modifying specific fields in a resource

Each method is designed for specific operations, ensuring clarity and proper organization of HTTP operations.

Heroku

Amplify your impact where it matters most — building exceptional apps.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (2)

Collapse
 
aein_bagheri_10ffa69696b9 profile image
Aein

سلام

Collapse
 
hemantgovekar profile image
Hemant Govekar

hello brother

Image of Quadratic

Python + AI + Spreadsheet

Chat with your data and get insights in seconds with the all-in-one spreadsheet that connects to your data, supports code natively, and has built-in AI.

Try Quadratic free

👋 Kindness is contagious

Dive into this insightful write-up, celebrated within the collaborative DEV Community. Developers at any stage are invited to contribute and elevate our shared skills.

A simple "thank you" can boost someone’s spirits—leave your kudos in the comments!

On DEV, exchanging ideas fuels progress and deepens our connections. If this post helped you, a brief note of thanks goes a long way.

Okay