Artikelen over: API

Updating information (PUT vs PATCH)

When in doubt, always prefer PATCH to PUT!

There are 3 endpoints per resource which you can use to perform updates. The first one is PUT, which completely replaces the entity with the provided payload. This is not handy for big entities with many properties. Therefore we provide two variants of the PATCH method: Json Patch and Json Merge Patch. Json Merge Patch is the most trivial because it allows you to only define the properties that you want to update. Json Patch is different but more powerful. Two examples:

Json Merge Patch


This example only updates the surname of the employee but leaves the rest untouched.

PATCH /api/v2/employees/8 HTTP/1.1
Content-Type: application/merge-patch+json
Authorization: Basic xxxxxxxxxx

{
    "surname": "Van Robaeys"
}


Json Patch


This example only updates the surname of the employee and adds a certificate called 'Rijbewijs' to the list but leaves the rest untouched.

PATCH /api/v2/employees/8 HTTP/1.1
Content-Type: application/json-patch+json
Authorization: Basic xxxxxxxxxx

[
    {
        "op": "replace",
        "path": "/surname"
        "value: "Van Robaeys"
    },
    {
        "op": "add",
        "path": "/otherCertificates",
        "value": "Rijbewijs"
    }
]

Bijgewerkt op: 21/11/2022

Was dit artikel nuttig?

Deel uw feedback

Annuleer

Dankuwel!