REST question: PUT one performance, GET another?

Short version of the question:
Does a "GET" in a particular URI need to match what was a "PUT" for that URI?

I think no. That's why:

Given that a resource is an abstract thing that is theoretically unknowable by the client, when we do PUT, we should only send the view. Based on combing according to RFC2616, it is not exactly indicated what this means for a resource that has many (potentially endless?) Views, but here are my thoughts; let me know if you agree:

My expectation is that if I GOT a resource view, all other resource views in this URI should be consistent (potentially updated) as needed. In other words, you tell the resource "use this view to redefine yourself."

So I should be able to do this:

Put / resources / foo / myvacation
Content Type: image / jpg
...

And follow this:

GET / resources / foo / myvacation
Accept: image / png
...

and get an updated version of myvacation in a different format (assuming the server knows how to do this). By extrapolating this, this composite atomic “image + metadata” PUT must also be legal:

Put / resources / foo / myvacation
Content-type: multipart / form-data p>

Content-disposition: form-data; name = "Document"
Content Type: image / jpg
[..]
Content-disposition: form-data; name = "IPTC"
Content Type: app / iptc
[..]
Content-disposition: form-data; name = "EXIF"
Content-type: application / exif
[..]

And then, since the server-side content negotiation (RFC2616, section 12.1) can be based on everything, we can use the document content by default for this:

GET / resources / foo / myvacation
Content Type: image / jpg
[..]

or if you think that I am doing this section of RFC 2396, section 3.4 "The request component is a string of information that will be interpreted by the resource." means that the URI with the query string refers to the same resource as the URI without the query string (and is isomorphic to simply sending the application / x -form-urlencoded data to the resource), then this should also be legal:

GET / resources / foo / myvacation? content = exif
Content-type: application / exif
[..]

The PUT description says:

The PUT method requests that the private object be stored in the supplied Request-URI.

For me, this is pretty anti-REST unless you read it very liberally. My interpretation is "The PUT method requires that the resource be created or updated in the provided Request-URI based on the representation of the private object."

Later we will receive:

The main difference between POST and PUT requests is reflected in the different Request-URIs. The URI in the POST request identifies the resource that will process the enclosed object. This resource can be a process of accepting data, a gateway to another protocol, or a separate entity that receives annotations. In contrast, the URI in the PUT request identifies the object enclosed with the request - the user agent knows what the URI is, and the server SHOULD NOT try to apply the request to another resource.

We also need to read this creatively, but the key bits here are “know what a URI is” and “apply a request”.

So, for me, the representation returned by the GET at the given URI does not have to be the same representation that was the PUT for the given URI, it just needs to be consistent.

True or false?

+6
content-type rest uri mime
source share
4 answers

Based on the fact that content negotiation can return different views from the same URI, I am pretty sure that what you use should not be the same as what you retrieve.

+5
source share

Your assumptions are correct. GET does not have to return the same view as you, but it must be the same resource.

I'm currently working on a web application that will return any resource as XHTML, JSON, or a custom XML dialect, depending on what you ask for in the content negotiation headers. Thus, the default browser will see HTML. Other HTTP clients, including XMLHttpRequest, can receive JSON, etc. They all represent the same resource in the same URI.

Similarly, our application will accept PUT or POST in any of the supported formats (taking into account the semantics of a particular resource or collection in question).

+3
source share

I agree with the other answers that the resource you PUT should not be the same as the one you later get. I wanted to add some of my experience to this issue in this area.

You must be very careful when relying on content negotiation. It is very difficult to get the right, and if you do not get it right, this will lead to unpleasant user problems. Let's make an example based on images ...

If Alice exposes the image in raw format, then Bob can RECEIVE the image as jpeg (via raw-> jpeg conversion on the server side), and Alice can RECEIVE the image in raw format; No problems. However, if Bob PUTs jpeg, then there is no way to return to the raw format for Alice. In the case of vacation photos, the absence of symmetrical transformations may not be a big problem, but in medical images it will be.

Another area in which the absence of symmetrical bite transformations is in representations where one has a circuit and the other does not. In this case, on the server side, you get agreements on how to convert them. But you encounter big problems when dealing with documents with diagrams that change over time and are not subject to control. Each time you change the schema, you must update all your transformations for the new form of the schema, while preserving all the resources using the old schema. Content consolidation is quickly becoming more complex than its value, with the exception of a few limited circumstances. One area where it can be managed is the complete control of the presentation of resources and its underlying schema. Another area is if resource formats are standards and allow you to do symmetrical conversions between different formats.

+2
source share

If you transform, then it makes sense that you PUT not that you are GET , so I don’t understand why this is a problem.

But if you are a PUT user with certain information, then when you use GET , then he should get this person, just like when I put my fourth photo for vacation, when I call GET , I expect the photo, but it can be converted by converting to another format or other transformations, but if I get the 5th photo, then this is a problem.

+1
source share

All Articles