elm-jsonapi icon indicating copy to clipboard operation
elm-jsonapi copied to clipboard

Can't encode data for patching

Open obmarg opened this issue 7 years ago • 2 comments

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 avatar May 22 '17 17:05 obmarg

@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.

noahzgordon avatar Jun 15 '17 18:06 noahzgordon

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

noahzgordon avatar Jun 15 '17 18:06 noahzgordon