title: Sending JSON object in Rails via Post
body: <p>This is a pretty straightforward question and I'm trying to bridge the gaps in my knowledge. </p>
  
  <p>Quite simply the applications work as follows:
  1: i: web app creates a hash of values
  1: ii: Turns this hash into JSON
  1: iii: Sends the JSON across to another application via POST
  THIS IS THE MAIN QUESTION</p>
  
  <p>2: i: other web app receives the JSON, deserializes and turns back into an object.</p>
  
  <pre><code>@hostURL = 'http://127.0.0.1:20000/sendJson'
  </code></pre>
  
  <p>For 1 I've got i and ii done. Not too difficult.</p>
  
  <pre><code>@myHash = HASH.new
      @myHash =
      {
        "myString" =&gt; 'testestestes'
        "myInteger" =&gt; 20
      }
  
      @myJsonHash = @myHas.to_json
  </code></pre>
  
  <p>Sending a post request in my application looks like this:</p>
  
  <pre><code>  res = Net::HTTP.post_form(URI.parse(@hostURL),
      {'myString'=&gt;'testestestest, 'myInteger' =&gt; 20})
  </code></pre>
  
  <p>However I'm at a loss as to how to send the JSON hash across through post.</p>
  
  <p>As for 2:</p>
  
  <pre><code>  @request = UserRequest.new({:myString =&gt; params[:myString], :myInteger =&gt; params[:myInteger] })
             if @request.save
      #ok
        puts "OBJECT CREATED AND SAVED"
      else
      #error
        puts "SOMETHING WENT WRONG WITH OBJECT CREATION"
  </code></pre>
  
  <p>Would this suffice as I hear Rails automatically deserializes on receiving a request.</p>
  
  <hr>
  
  <p>On a side note: What should the response be?</p>
  
  <p>These are 2 web apps communicating so returning some html would be bad. Possibly a numeric response? 200? 404?</p>
  
  <p>Are there any industry standards when it comes to responding with data rather than responding to a browser</p>