HTTP GET sets internal data, still considered RESTful?

As I understand it, an HTTP GET request should return the requested data and is considered RESTful if it is safe (read-only) and idempotent (without side effects).

However, I would like to implement a service to display new items since the last visit using the URI /items/userid/new , can this be RESTful?

When returning data, items sent in response to a GET request should be marked as read in order to keep track of what's new. Labeling these elements will violate both the safe requirement and the idempotent requirement.

Does this mean that .../new never considered RESTful?

+5
source share
4 answers

Very interesting question. I think the answer will be "implementation dependent" as there are various solutions that would meet the requirements of the business.

If every visit to the URL /items/userid/new by the same user changes the database entries, then this is not a "safe method" and will not correspond to the generally accepted REST pattern.

If you filter new elements in the view, but without any corresponding database changes with each GET call, this will certainly be RESTful. For instance:

 /items/userid/new?lastvisit=2015-12-31 

or

 /items/userid/new?last_id=12345 

or saving a list of viewed items on the client side will certainly be eligible.

+3
source

Usually we decide for him the methods of servicing and supporting the protocol. In the case of HTTP, we use GET, POST, PUT ... etc. Typically, Get is used to get some state of the application that will be displayed with hypertext.

Here /items/userid/new may be a new service that returns a list. Any modification on this list will be a subsequent request with a different association of methods.

0
source

Keeping track of items already visited should not be the responsibility of the server. The client must repeat the items already visited. This leads to improved scalability and loosely coupled systems, since the server does not have to process these parameters, for example. thousand customers.

To deliver fresh items that you could, as Cahit has already touched, provide a feed that includes all items for a temporary or fixed number of items. Typically, an archived feed is a good choice.

As a result of this, the client can scan your channel on its own to receive all new items.

0
source

An interesting question indeed.

For a simple URL, I would not do that. One reason, for example: I remember sending testmail with a unique link pointing to our own web server. After going through the ISP mail server, a request was made with this URL to our server. This was done using a spam filter to check if the URL exists. So, if a letter was sent to the client, saying: “Look here for new items”, they would disappear even before the mail was received.

And you, of course, would not want this simple URL to appear somewhere in the search results or be used to preload pages.

On the other hand, if a request was made during login (or using a cookie), this may be normal.

Maybe this is what it does when we review our statistics / responses.

0
source

Source: https://habr.com/ru/post/1239819/


All Articles