I'm just starting to try to understand the principles of REST design and struggle with the first example I'm trying to do.
Let's say that I want to make a REST API design for something like an SSH session. Ignoring security, logging in, etc., I assumed that there would be something like a URI / session URI, and I would initiate an SSH session by POSTing in / session, defining the connection information, hostname, username. This will cause the web server serving the REST API to start an SSH session on my behalf, assign it some kind of identifier, and return the URI / session / [id]. Then I could interact with this session with sub-resources of this URI. This is not a desperately good analogy to what I want to do, but it does have a significant point: trying to define an interface for something that has a “session” and whose state changes when I send things to resources inside it.
Now my problem is its scalability, but I can't think of anything better. It relies on the web server initiating the SSH connection to the host, and this connection must be supported by the web server (therefore it will be lost if the web server needs to be redesigned). It also associates my request with one web server - I could not, easily, have a farm of web servers that process API requests.
I could move the creation and maintenance of SSH connections to another server somewhere, but this only really moves the scalability issue. And in general, then I need to define an API for this server, and why not make it a REST API, in which case I just got a duplicate of the first, ad infinitum.
Now I can just look at it wrong, not being resourceful enough, but, in my opinion, here the “resource” is an SSH connection. My problem is that the resource is not something that is easily shared - it is what the web server creates and is essentially transient.
Are there any RESTful API API gurus that can help me move the best way? Please note that I really do not think it is really REST-specific - a significant design problem has arisen. I imagine that I have ever taken an approach to developing this as a web service on the basis that the tent for interacting with web services was not stateless.
Thanks.
[EDIT:] Another problem with this approach is the “leak” of “session” resources when clients do not explicitly delete them. The most reasonable solution I can come up with for this is to define some session property (possibly customizable at creation, possibly a fix) that determines the time during which you need to contact the session again before it is considered obsolete and deleted . The client will get access to this property (for example, / session [id] / keepalive or something else), which will return the timestamp, split it into two (make a good time interval halfway between time and then) and make sure that if nothing he will not “interrogate another,” the server, again turning to the same resource until this time. If this fails, the session will be restored. This is the very “RESTful” approach that I can think of, but would appreciate the more experienced RESTful thoughts.