DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Database Bottlenecks Nobody Talks About: Optimizing SQL Queries Beyond Indexing
  • Seeding Postgres When Your Schema Has Foreign-Key Cycles
  • Applying Oracle 19c Release Update (RU): A Practical Guide from My DBA Experience
  • The Aggregate Reference Problem

Trending

  • Member Spotlight: Srinivas Chippagiri
  • The Self-Hosting Math Changed While We Were Still Arguing About Sovereignty
  • PWA on iOS, Part 3: Chrome on iPhone Is WebKit Too. How One Engine Sets the Rules for PWAs on iOS
  • How to Hide Sensitive Information Before You Share a File

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Data Engineering
  3. Databases
  4. Do You Need PUT and PATCH?

Do You Need PUT and PATCH?

Find out if your really need PUT and PATCH.

By 
Greg Brown
·
Updated Apr. 05, 19 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
13.5K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

Conventional wisdom says that REST APIs should be implemented as follows:

  •  GET — read
  •  POST — add
  •  PUT/PATCH — modify
  •  DELETE — remove

This mostly works well. Query parameters can be used to supply arguments for GET and DELETE operations.  POSTs can use either URL-encoded or multipart form data, standard encodings supported by nearly all web browsers, and other HTTP clients.

Image title

However, it doesn't work quite as well for PUT  or PATCH. PUT has no standard encoding and requires the entire resource to be sent in the payload. PATCH was introduced as a workaround to this limitation, but it also lacks a standard encoding and is not supported by all clients (notably Java).

However, the POST method can also be used to modify resources. The semantics of POST are less strict than PUT, so it can support partial updates like PATCH. Further, the same encoding used for creating resources (either URL-encoded or multipart) can also be used for updates.

For example:

  • POST /products — add a new resource to the "products" collection using the data specified in the request body  
  • POST /products/101 — update the existing resource with ID 101 in the products collection using the (possibly partial) data specified in the request body

This approach works particularly well when resources are backed by relational database tables. An "add" POST maps directly to a SQL INSERT operation, and a "modify" POST translates to a SQL UPDATE. The key/value pairs in the body (whether URL-encoded or multipart) map directly to table column names and values.

The approach also supports bulk inserts and updates. POSTing a URL-encoded payload works well for individual records, but JSON, CSV, or XML could easily be used to add or update multiple records at a time.

So, do you really need PUT and PATCH? Given that POST is more flexible, better supported, and can handle both create and update operations, I'd say no. Please share your thoughts in the comments!

Database Relational database Patch (computing)

Opinions expressed by DZone contributors are their own.

Related

  • Database Bottlenecks Nobody Talks About: Optimizing SQL Queries Beyond Indexing
  • Seeding Postgres When Your Schema Has Foreign-Key Cycles
  • Applying Oracle 19c Release Update (RU): A Practical Guide from My DBA Experience
  • The Aggregate Reference Problem

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook