title: How, in Sinatra, to pass a Request Body to other classes?
body: <p>I'm using a Sinatra app to receive server requests and I want to dissect them in a separate class I call "request", but when I pass the request object the body gets dropped.  Trying to read the request.body in the main class works but trying to read it in the new class generates a JSONparser octet error.</p>
  
  <p>In the main Sinatra file, this test call generates the correct response:</p>
  
  <pre><code>puts JSON.parse request.body.read
  </code></pre>
  
  <p>after, I pass the request to the Request Class with the code below.</p>
  
  <pre><code>req=Request.new(request)
  </code></pre>
  
  <p>But in the Request class initialization def, the same "puts" code above generates the error:</p>
  
  <pre><code>JSON::ParserError - A JSON text must at least contain two octets!:
  </code></pre>
  
  <p>Both files include the JSON requirement.</p>
  
  <p>A work around is fairly simple but I would prefer the more elegant solution if I could figure out why it is not working as I expect.  Any thoughts are appreciated.  </p>