Update a Person

If you have been following along, we have created ‘Person’ entities, read ‘Person’ entities both in bulk and by ‘id’ key. We are now going to take a look at updating an existing ‘Person’ entity.

Read ‘Person’ entity 10000001 from the database as shown in the Get a Person example.

Once you have successfully read ‘Person’ entity 10000001 into your Postman session, copy the content of the response body to your clipboard. Next, create a new tab in Postman and paste the content of the GET response into the new request’s body. Set the new request’s target URL to http://127.0.0.1:8080/person/10000001 and ensure that the http verb is set to PUT. Next, add the following key-value pair to the http header:

  • Content-Type : application\json

Now edit the new request’s JSON body so that Opus’s full name is given along with an accurate weight and driving ability. Strictly speaking, you do not need to include the ‘id’ or ‘href’ fields in an update, but it does not hurt to do so as the application runtime will ignore them in the case of an update operation. Remember that the key (id) of the ‘Person’ entity we are updating is specified in the update request’s URL.

    {
        "id": 10000001,
        "href": "http://127.0.0.1:8080/person/10000001",
        "name": "Opus the Penguin",
        "age": 8,
        "weight": 385,
        "valid_license": false
    }

When you have finished, you should have something that looks as follows. Click ‘Send’ to issue the PUT request to the application. l2-update-person-a

The PUT request should update the entity using the ‘id’ key as its update criteria, and then return a JSON representation of the updated entity. This is a little different than standard PUT/MERGE approaches, where the result of an update is measured simply by the http response code. If you don’t like the way the application handles update operations, it is very easy to update the generated source code to omit the response body following a PUT.

l2-update-person-b