View Savon Request XML without Sending to Server View Savon Request XML without Sending to Server xml xml

View Savon Request XML without Sending to Server


Using Savon 2 I do it this way, write a method that return the request body from the client.

 client = Savon::Client.new(....)

this is not mentioned in the documentation

  def get_request     # list of operations can be found using client.operations     ops = client.operation(:action_name_here)     # build the body of the xml inside the message here             ops.build(message: { id: 42, name: "Test User", age: 20 }).to_s  end


You can directly via the Savon::Client#build_request method.

Example:

request = client.build_request(:some_operation, some_payload)request.body # Get the request bodyrequest.headers # Get the request headers

Take a peak @ https://github.com/savonrb/savon/blob/master/lib/savon/request.rb for the full doc.


I am using Savon 2.11 and I can accomplish it with globals in the client:

def client  @client ||= Savon.client(soap_version: 2,                           wsdl:         config.wsdl,                           logger:       Rails.logger,                           log:          true)end

More info on the globals here.

Then the logger spits out the host, the http verb and the complete xml ("headers" and body) for both request and response.