title: How to test a JSON REST API
body: <p>I'm brand new to ruby (first day working with ruby) so please forgive any novice questions and lack of understanding.</p>
  
  <p>I'm trying to validate the responses to http callouts.</p>
  
  <p>For example, let's say the endpoint is the following: </p>
  
  <pre><code>https://applicationname-api-sbox02.herokuapp.com 
  </code></pre>
  
  <p>And, I'm trying to authenticate a user by sending a get request like this:</p>
  
  <pre><code>get_response = RestClient.get( "https://applicationname-api-sbox02.herokuapp.com/api/v1/users", 
                      {
                          "Content-Type" =&gt; "application/json",
                          "Authorization" =&gt; "token 4d012314b7e46008f215cdb7d120cdd7",
                          "Manufacturer-Token" =&gt; "8d0693ccfe65104600e2555d5af34213"
                      }
                  ) 
  </code></pre>
  
  <p>Now, I want to validate the response and do the following:
  - parse the response to ensure that it is valid JSON
  -  do some validation and verify the JSON has the correct data (verify that id == 4 for example)
  - if an error is encountered, raise an exception using the 'raise' method.</p>
  
  <p>In my first feeble attempt I tried the following:</p>
  
  <pre><code>puts get_response.body
  if get_response.code == 200
  puts "********* Get current user successful"
  else
  puts "Get current user failed!!"
  end 
  </code></pre>
  
  <p>Now, this returned that getting the current user was successful, but how do I actually parse the json, verify the correct id, and raise an exception if an error occurred?</p>