elm-jsonapi
elm-jsonapi copied to clipboard
Can't encode data for patching
I'm writing some an admin frontend over the top of a jsonapi backend. As part of this, I need to be able to make updates to some models via http patch. One of the requirements of a jsonapi patch is:
The PATCH request MUST include a single resource object as primary data. The resource object MUST contain type and id members.
However, elm-jsonapi doesn't seem to provide a way to set an ID on data to be sent to the server. The only method in JsonApi.Encode
is clientResource
, and there is no way to set a non-UUID ID on a ClientResource
.
@obmarg the rationale here is that a clientResource
is only supposed to be a resource generated by the client, which does not have knowledge of the IDs present on the server. In order to PATCH an existing resource, it first must be fetched from the server.
I hope to soon implement post
and patch
methods for the library elm-jsonapi-http
, which should solve for your use case. This will also allow me to move the Encode
module, which shouldn't need to be exposed in the first place.
To unblock you, however, I will move toward adding a resource
method to the Decode
module before revising the functionality. This should allow you to encode a resource fetched from the server to use as the body of a POST request.
I also know that this kind of functionality isn't really useful unless you can modify the attributes and relationships of an existing Resource, so I'll get to work on that too :D