Mastercard / terraform-provider-restapi

A terraform provider to manage objects in a RESTful API
Other
808 stars 217 forks source link

Support the PATCH method to update resources #150

Closed asnowfix closed 2 years ago

asnowfix commented 3 years ago

Was adding support for https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH / https://datatracker.ietf.org/doc/html/rfc5789 ever be considered here? MDN makes it clear that it might not be idempotent, but some API providers do not support PUT.

DRuggeri commented 3 years ago

Hey there, @asnowfix - I think this is already possible by leveraging the updateMethod - have you tried that out?

NicoK commented 3 years ago

I was successfully using PATCH for create_method and update_method, so that seems to be working

asnowfix commented 3 years ago

@NicoK , do you mean that the provider knows how to generate a PATCH on multiple properties based on resource update where multiple fields are changed? I will have a look: I possibly wrongly assumed that multiple PATCH calls would be required, one per changed property.

DRuggeri commented 3 years ago

Ah, yes - what you describe, @asnowfix wouldn't be something this provider is capable of supporting. Today, we don't have a way to know exactly which properties changed, so wouldn't be able to calculate the delta of individual properties to PATCH.

What would happen on a change: the full contents of the data element will be sent as body with the update_method

asnowfix commented 3 years ago

Thanks @DRuggeri : no diff. Would the code supporting the PATCH verb support building a proper "op"-based payload structure as defined in RFC5789, attempting to set all properties, or would it use the PATCH verb with the PUT payload structure?

DRuggeri commented 3 years ago

NP, @asnowfix. The payload would be exactly the same as what is specified in the data element. Said another way, it uses the exact same HTTP request as PUT... but instead just uses the PATCH (or whatever is set in update_method) verb.

Reading the RFC shared, it doesn't seem like a standard way of defining what changed in the body has been developed which would mean that this is in API-specific territory to be defined.

inviul commented 2 years ago

I want to make PATCH api call using resapi provider, but, neither create_method nor update_method working for me.

Error: unexpected response code '400': {"$id":"1","innerException":null,"message":"Permissions request cannot be null","typeName":"System.InvalidOperationException, mscorlib","typeKey":"InvalidOperationException","errorCode":0,"eventId":0}

DRuggeri commented 2 years ago

It's been a while since OP has responded, so will close this out. @inviul, your comment seems like a separate issue altogether. If so, can you create a new issue?