Speedychuck Speedychuck - 2 years ago 204
Ruby Question

Ruby - API RestClient - JSON

Just getting started with API testing and struggling, used to just doing front end selenium web-driver tests, however, I need to get my head around API testing.

I kind of understand the basics such as Get will get the data from the url and post will post data to the url, I think that is correct, however, I could be wrong.

The issue I am having is below:

response = RestClient.post 'http://jsonplaceholder.typicode.com/posts',

{:title => 'mr', :first_name => 'bob', :second_name => 'smith'}

data1 = JSON.parse(response)

p data1

So I am assigning the restclient.post to the response variable and posting the hash key, value pairs to the url? Then I am using JSON to parse the response and then printing the response to the console. What I need to do is extract each value from the hash and print each value to the console so it shows the data as mr bob smith. Instead of {:title => 'mr', :first_name => 'bob', :second_name => 'smith'}

Answer Source
print "#{ data1[ :title ]} #{data1[:first_name]} #{data1[:second_name]}"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download