T
T
trerums2014-08-31 22:06:06
ASP.NET
trerums, 2014-08-31 22:06:06

How to replace sessions in a RESTful application?

Good afternoon.
There is an application built according to all the rules of REST. But there was a need to implement the functionality of uploading files, and you need to check for the number of uploaded photos. In other words, at any point in time, the backend must know about the files uploaded by the user. That is, in fact, the sessions suggest themselves.
The problem is that from the very principle of REST it follows that each request to the server must be self-sufficient, contain all the necessary information for its processing, i.e. the server must not store any session data. I'm using the ASP.NET WEB API, and because of this, sessions are not even available here (this can be bypassed, but it will be a hack). Everywhere I read, they write that if there is a need to use sessions in a REST application, then you need to redesign your application. But no one says exactly how, everyone is smart, everyone writes articles, but only in theory.
The question is: how can you achieve what you want without resorting to storing state on the backend between requests? I'm not asking for a ready-made solution, suggest an idea if you know how to solve the issue.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nazar Mokrinsky, 2014-08-31
@nazarpc

Store the state in the database, you can connect to it from anywhere. The advantage of RESTful applications is that statelessness on the server allows you to scale the system if necessary by simply cloning nodes, since all nodes are equal. Storing sessions in the database does not interfere with this in any way.

R
Roman, 2014-09-18
@uaKorona

If I understood correctly, then you are implementing a functionality that allows your user to upload a certain number of photos. This assumes that you can identify the user each time they upload files.
If so, then your backend can identify the user on each request and get information from the database about how many photos have already been uploaded for this user.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question