
In the end, we really only care about the vendor-specific namespace, but In most cases the actual request and response will belong to a The SOAP envelope is structured from elements in several namespaces, and Up a little about them first - A Gentle Introduction to Namespaces. If you don't know much about how XML namespaces work, I suggest you read
#Ruby http client code#
That we're already comfortable with, reducing the learning curve, and ensuring that the code is easy to maintain.Īdd gem 'nokogiri' to your Gemfile if you haven't already. We also find that Nokogiri is so heavily used elsewhere that it's a tool Library that can handle XPath and namespaces, and do it quickly. Producing and consuming a fair bit of XML using this technique, so we need a Nokogiri is a fast, feature rich XML library. The end about making parallel requests using Typhoeus::Hydra. We will focus on sequential requests to start with, with some notes at To use it, just add gem 'typhoeus' to your Gemfile. Without needing to stub out more than is necessary. Much easier - we can easily stub out requests to return fixture data Typhoeus is also structured in a way that makes testing our SOAP client Won't be so exciting, but if you have cause to make multiple SOAP requestsĭuring the request cycle, this can dramatically speed up the process. If you are making requests in the background using rake tasks or DJ this It's fast,īut most importantly it gives us the option to perform parallel Typhoeus is a Ruby HTTP client that uses curl under the hood. Generated code code can also force the server's naming standards upon the client, which may not be desirable. We have also found drawbacks with this approach, including the generatedĬode being brittle and hard to maintain. In Ruby thisĬan tend to be overkill unless you are dealing with a particularly Typically, SOAP Clients in strongly typed languages tend to be in theįorm of code automatically generated from a WSDL definition. Rolling your own SOAP client isn't always necessarily the best way to Tools like SOAP Client can parse these, and can help you to get an idea of what a valid request might look like. Many servers will provide machine-readable documentation for their API using this format, and this can provide handy documentation if the human-documentation is lacking.Ĭheck your vendor's documentation for details, or try adding ?wsdl to the end of the service URL. Whilst not strictly part of SOAP, it can also be useful to be aware of WSDL, which is an XML format for describing a web service. Whilst this is a very simplified explanation, we can think of a SOAPĬlient as just sending and receiving structured XML. The response is serialised into XML and returned in another strictly Where the request parameters are parsed, the relevant server side code is run, Strictly formatted SOAP "Envelopes" are crafted and sent to the server, There is also a document style approach for SOAP, but the RPC approach seems to be far more common. In most cases it is a RPC-style protocol, meaning that you are dispatching requests to run a particular method on the server, as opposed to a RESTful API where you deal primarily with documents.

SOAP is a web service protocol using XML over HTTP.
#Ruby http client full#
The full code for this post is available on GitHub.

You can apply the techniques in this post for XML-RPC too - it's a much simpler XML format - but we won't be documenting it here. Today we are going to look at consuming SOAP interfaces using some lightweight Ruby with the help of Typhoeus and Nokogiri. Saddled with little or lacklustre documentation. If we are super lucky, they even confirm to what ActiveResource expects, and will be trivial to implement.īut often luck leaves us wanting, and we have to integrate with legacyĪpplications offering only SOAP or XML-RPC APIs.

If we are lucky, these are clean, well documented, RESTful APIs which make our heart sing. As our applications become better connected with the net in general, we find we need to communicate with 3rd party services.
