0

I have a Sinatra app where I want to get client input, as demonstrated in the following pseudo-code:

get '/foo' do
    "doing some stuff"
    foo = getInputFromClient
    foo
    "continuing to do more stuff"
    foo = getInputFromClient
    foo
    "done"
end

This is the output that I would like to see at the client end:

curl http://127.0.0.1:4567/foo #start the request
doing some stuff
#Somehow submit "shoop" to Sinatra
shoop
continuing to do more stuff
#Somehow submit "woop" to Sinatra
woop
done

I can't split this up into two curl calls. How do I accomplish this? Should I not be using Sinatra in the first place? Do I have to switch to sockets?

I have read these other questions which do seem related, I'm not familiar enough with what they're talking about to see if it applies to me or not. A simplification of the other questions to my case or a few keywords to Google would be appreciated.

Community
  • 1
  • 1
Seanny123
  • 8,776
  • 13
  • 68
  • 124
  • Why can't you split this into two cURL calls? – the Tin Man Oct 17 '13 at 06:29
  • Because I wanted to keep the state. I realize now that this is possible, but due to some reasons that are specific to my situation. I'll accept your answer, but I'll note that for my case where I was just trying to get two programs to talk to each other, using `sockets` ended up just being more practical. – Seanny123 Oct 17 '13 at 06:42

1 Answers1

1

Typically we'd write something more like this:

get '/foo' do
  ...do something...
  "done doing foo"
end

get '/foo2' do
  ...do something...
  "done doing foo2"
end

get '/foo3' do
  ...do something...
  "done doing foo3"
end

And the client would see a connection handshake like this:

  1. Connect to /foo.
  2. Get "done doing foo" response.
  3. Connect to /foo2.
  4. Get "done doing foo2" response.
  5. Connect to /foo3.
  6. Get "done doing foo3" response.

Both the client and server ends have to have some code written to handle the logic. You can't send a message back to cURL in the middle of a connection, have it return more information, request more data and have it returned. That's not how cURL works, nor the HTTP protocol.

It's possible to use various technologies with a browser to talk back and forth, but cURL isn't a browser.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303