--
You received this message because you are subscribed to the Google Groups "HAL Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hal-discuss...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/hal-discuss/f7bbb51c-37c1-4efc-9175-2d78885dfb5bo%40googlegroups.com.
My guess is that your relationship update is part of a certain business operation. What I usually do is to model business operations as actions on the resource. In this case I would add an "BusinessOperationX" link to your ressource. Clients would then (a priori) know that POSTing to that action link means "Here is the data you need to perform your business operation server side - I don't care what it involves, just do it". The data then contains a reference to the other resource that you want to relate to the first resource. The reference may be either a simple identifier or a URL depending on the scenario.
POSTing (or PUTing) URLs as relationships is generally a bit dangerous in closed systems, as a client might POST a URL pointing to something completely unexpected (google.com for instance?). On the other hand, if you allow links between unrelated systems, then URLs are good to go - but maybe you should GET the resource pointed to and validate it before allowing the update.
Idempotency is solved by supplying a transaction/operation identifier (GUID) with the rest of the data. The server then keeps track of already executed actions to avoid multiple executions of the same operation.
To unsubscribe from this group and stop receiving emails from it, send an email to hal-d...@googlegroups.com.
{
_links: {
self: '/foo/bar',
collection: '/foo',
author: 'https://evertpot.com/',
},
title: 'Hello'
}
I would not dismiss a PATCH format on the premise of loosing idempotency. Using a custom PATCH format can always introduce specific constraints and rules that makes PATCH quite safe. Not necessarily idempotent but is that actually a hard requirement?
You could for example define a PATCH media type that behaves more or less like a PUT but per definition only allow changes to specific link relations, ignoring the rest. So if you would send back the resource as is or only containing relevant links, the end result would be the same.
Existing PATCH formats like http://jsonpatch.com/ might actually work for this if you introduce additional processing constraints that only allow change operations on some link relations. And you can always require that requests include a test operation on the value of a suitable state property to minimize the risk of missed state changes.
Experience from using Java libraries for processing specific JSON Patch operations has actually been quite positive. So using a generic PATCH format don't require that you allow patching everything on the resources. Specific constraints can still be dictated by the business logic in question.
-Fredrik