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
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  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.

Greg Brown user avatar by
Greg Brown
·
Apr. 05, 19 · Tutorial
Like (1)
Save
Tweet
Share
12.17K Views

Join the DZone community and get the full member experience.

Join For Free

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.

Popular on DZone

  • How Agile Architecture Spikes Are Used in Shift-Left BDD
  • Building a REST API With AWS Gateway and Python
  • Best Practices for Writing Clean and Maintainable Code
  • Key Elements of Site Reliability Engineering (SRE)

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: