Gizra / elm-restful

Elm utilities useful for working with a RESTful backend (especially Drupal)
MIT License
3 stars 0 forks source link

Allow Patching with a different type #15

Closed amitaibu closed 6 years ago

amitaibu commented 6 years ago

I have a My account page that I'd like a user to be able to update.

type alias MyAccount holds some properties that can be related to the type alias User, but it's only a subset and some fields and some are not in the User at all (e.g. a password field, which a user may update).

So, my case is PATCH a MyAccount and get a result of a User. If that would have been a create operation I could have:

endpoint : ReadWriteEndPoint Http.Error UserId User MyAccount ()

Maybe we should expose also the Patch type in the signature?

rgrempel commented 6 years ago

You can use patch or patchAny to cover that case.

Now, we could simplify the type signature for patch if we allowed only one patch type (so that it was in the config itself). However, I think it will sometimes be the case that we want to patch in several different kinds of ways -- for instance, we might send just one field in one case, and just another field in another case. So, I think it's probably best to delay specifying the patch type to when we actually call patch, rather than putting it in the config.

(The exception is patchFull, since in that case we have the encoder in the config anyway).

amitaibu commented 6 years ago

Makes sense, thanks!