Modifying a global resource can feel a bit weird, but essentially as an authorized user, you are looking at your customized representation of the resource, and not just a direct 1:1 of whats in the database.
- Like:
PATCH /bars/123
with fieldliked: true
- Unlike:
PATCH /bars/123
with fieldliked: false
This can feel a bit weird if you consider it as corrupting the global value, but headers often change the response and that's probably fine. It can be weird to show different attributes depending on the user (I avoid this) but you can probably jam it in meta
as the JSON-API allows this already? It's relevant data, just not necessairily part of the resource.
Likes are a subcollection, which you can add and delete too.
- Like:
POST /bars/123/likes
- Unlike:
DELETE /bars/123/likes/XYZ
Likes are a JSON-API relationship with their own relationship URL on the resource.
- Like:
POST /bars/1/relationships/likes
- Unlike:
DELETE /bars/1/relationships/likes/XYZ
This is simple and very like just doing usual resources, but a resource might have more information than the relationship collection, which is just the basics:
{
"data": { "type": "people", "id": "myidnumber" }
}
Feels a bit weird telling the API you're a person though ey?
Make your very own little land of likes:
- Like:
POST /me/relationships/likes
- Unlike:
DELETE /me/relationships/likes/XYZ
You then get to send
{
"data": { "type": "bar", "id": "123" }
}
Seems a bit cleaner, and leaves the usual /bars/123/likes
to be a collection of full fat resources.