How to deal with GET request and (not to) changing the application state?

341 views Asked by At

This is a generic question about GET method.

Imagine I need to store the last pagination size selected by the user:

+-------------+   +-------------+    +--------------------+    +----------+
| Size change |-> | GET request | -> | Server store pref. | -> | Response | 
+-------------+   +-------------+    +--------------------+    +----------+

Browsing a list of products is of course a GET request and changing the paging size is a GET request too (we change only the size parameter):

<ul>
    <li><a href="/catalog/browse/size=10&page=1">size 10</a></li>
    <li><a href="/catalog/browse/size=25&page=1">size 25</a></li>
    <li><a href="/catalog/browse/size=50&page=1">size 50</a></li>
</ul>

Every time the user changes the size I need to store the new size in my backend.

How to deal the the fact the GET should not change the state? Issuing a query (thus changing the state of the application) fees so wrong to me. Is there any alternative?

GET Requests a representation of the specified resource. Requests using GET should only retrieve data and should have no other effect.

0

There are 0 answers