0

For example I have an object such as

{
    ID: 1000,
    Type: "Ticket",
    "Followers": [
    {
    "UserID": 1200
    },
    {
    "UserID": 1201
    },
    {
    "UserID": 1202
    }]
}

If I wanted to update this object using a new request, how would a list Followers be treated?

For example if a send this update request using PUT, would it mean that there are no changes in Followers, or that Followers is not empty?

{
    ID: 1000,
    Type: "Ticket",
    "Followers": []
}

1 Answer 1

1

I suppose you are designing the API and you are not referring to an existing API.

First I understood that you are talking about a RESTfull API?

Therefore most of the time you will have an endpoint dedicated to update a specific parameter.

For example to update the followers:

PUT/PATCH /api/ticket/1000/followers

Providing an empty array or null value to this request would then mean that you are removing your followers.

Or you can also implement DELETE HTTP method. The idea would then to use PUT only for an update logic - it will then returning an error if you provide and empty/null value.

In that case the only way to delete the followers will be to use the DELETE HTTP method:

DELETE /api/ticket/1000/followers

But once again it will depends of how you want to implement it and what seems the most usable and logical for you and the end users.

Edit: Your question was related to the usage of the single endpoint /api/ticket/1000 without sub resources.

Therefore, sending the following object in PUT without providing "Followers" will not change/delete followers.

{
    ID: 1000,
    Type: "Ticket"
}

At the opposite, providing a key for "Followers" in your request will update the value of the followers. In that case it will delete them:

{
    ID: 1000,
    Type: "Ticket",
    "Followers": []
}
Sign up to request clarification or add additional context in comments.

3 Comments

I understand your reasoning, but I want to do it from a single enpoint /api/ticket/1000, not subresource /api/ticket/1000/followers
In that case you can either provider or not the key "followers" from your object. So if "followers" is provided this will replace the existing. So if followers is empty, followers will be removed. And at the opposite if the key "followers" is not provided then nothing will happens to followers.
@mko I've updated the answer accordingly to provide you with an example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.