Should I Use POST, PUT, or PATCH to Add Data?
What's the Difference of these three calls in the Pillars API?
Questions:
-
Why are there three different ways to add data to a record through the API?
-
What’s the difference between Post, Put, and Patch when submitting record changes through the Pillars API?
-
When should I use Post, Put, and Patch when editing records through the Pillars API?
Main Points: -
Post = Create a new record.
-
Put = Replace a record and all its fields.
-
Patch = Replace or add individual fields leaving the remainder of the record intact.
Explanation:
The main difference lies in whether you are creating a brand-new item, replacing an existing one entirely, or just editing a specific field.
Key Differences at a Glance
-
POST (Create): Use this to create an entirely new record. It is not idempotent, meaning if you send the same POST request twice, you might accidentally create two identical records.
-
PUT (Full Record Update/Replace): Use this to completely replace an existing record. When using PUT, you must send the entire data object (all fields). If you leave a field out, the API may overwrite it with a null or default value. It is idempotent; sending the same replacement multiple times always results in the same final state. It does not create a duplicate record.
-
PATCH (Partial Update): Use this for minor modifications of a record. You only send the specific fields you want to change, e.g., just updating a user's email address. This is more efficient for large, complex resources when you don't want to re-upload the entire data set.
Comparison Table
| Feature | POST | PUT | PATCH |
|---|---|---|---|
| Primary Action | Create new resource | Replace entire resource | Update partial resource |
| Idempotent? | No | Yes | Sometimes |
| Payload Required | New resource data with all fields | Full resource of all fields | Only changed fields |
| Use Case | Adding a new customer | Resetting a user profile | Changing Active Status, editing an email address |
Important Note
While these are standard REST conventions, some specific implementations of the Pillars API may behave differently. For instance, some "Pillar Update" endpoints specifically use POST for updating a Pillar's configuration in certain frameworks. Always check the specific Pillars Reference Documentation for the exact endpoint you are using.
Updated 8 days ago