Ruby: Debugging and Testing APIs and Backend Services with Runscope

The Runscope Traffic Inspector lets you see all of the API requests and responses you're sending and receiving from your code. To capture the requests, create a Gateway URL for the API you're calling. Below are some examples for using the Gateway URL with your favorite HTTP client.


Net::HTTP POST Request Example Library Docs

require "net/http"
require "uri"

uri = URI.parse("https://yourapihere.com")

http = Net::HTTP.new(uri.host, uri.port)

request = Net::HTTP::Post.new(uri.request_uri)
request.set_form_data({"foo" => "bar", "fizz" => "buzz"})

response = http.request(request)

HTTParty POST Request Example Library Docs

require httparty
response = HTTParty.post("https://yourapihere.com", 
                         :query => { :foo => "bar" })
puts response.body, response.code, response.message, response.headers.inspect

Typhoeus POST Request Example Library Docs

Typhoeus.post("https://yourapihere.com", body: { foo: "bar" })

Faraday POST Request Example Library Docs

conn = Faraday.new(:url => 'https://yourapihere.com') do |faraday|
  faraday.request  :url_encoded             # form-encode POST params
  faraday.adapter  Faraday.default_adapter  # make requests with Net::HTTP
end

conn.post '/api', { :name => 'Maguro' }

Need help? We have you covered.

View the docs or contact our support team and we'll get back to you as soon as we're able to respond.