2

Let's consider that our PUT endpoint performs some data validation on the contents of the data. Then, is this scenario (in pseudo code):

  • data = GET
  • short latency happens, no update server-side
  • PUT data

=> always yielding a 200/2xx? Or would it be possible that the data is considered invalid by the PUT endpoint (4xx?)

In other words: should a service allow clients to read (GET) a resource representation that would be itself flagged as invalid (with respect to data validation) when sent on update (PUT)?

UPDATE: Note: this is not about media-types but actual data validation.

lajarre
  • 4,910
  • 6
  • 42
  • 69
  • 1
    How did the invalid state got stored into the resource in first place? In general if the same representation is used for the update that is returned by a previous GET I'd expect the request to succeed. In case some other update may interfer in between the GET and PUT request, better use ETag and conditional GET requests (If-None-Match) instead. – Roman Vottner Mar 31 '17 at 15:47

1 Answers1

1

When you perform a GET request you're asking for a representation of a resource. When you perform a PUT request, you're asking to replace the targeted resource with the one in the submitted representation.

So, if the same media-type is used for both representations, the server should accept it, but it's perfectly possible to have one media-type for PUT and another for GET.

should the server allow clients to read (GET) a resource that would be itself flagged as invalid when sent on update (PUT)?

That is determined by the Content-Type headers. An example is if the server allows clients to get a pretty formatted HTML document when the GET request is performed with Accept: text/html, but the clients have to update that resource with a application/json representation.

Pedro Werneck
  • 40,902
  • 7
  • 64
  • 85
  • My question is not dependant on media types (updated). It is rather about validity of the representation, knowing that the PUT endpoint can perform some data validation (not about the format, but the contents). – lajarre Mar 31 '17 at 15:19
  • @lajarre Your question depends on the media-type. As I said, what will determine if the action is acceptable or not is if the same media-type can be used for sending and receiving the representation. Recommended reading: http://stackoverflow.com/a/29586455/1202421 – Pedro Werneck Mar 31 '17 at 15:32