By: Najma Malik Category: Ruby on Rails,Web Development Technologies: Ruby on Rails
SOAP(Simple Object Access Protocol) is a standard API protocol specification for exchanging structured information between computer systems and applications.
We can implement all the REST API methods like GET, POST, PUT and DELETE with SOAP API Client object in the Ruby on Rails application by using the ‘Savon’ gem.
Savon Gem Installation:
Example Usage:
client = Savon.client(wsdl: ‘http://service.example.com?wsdl')
client.operations
# => [:find_user, :list_users]
# call the ‘listUsers’ operation
response = client.call(:list_users)
# call the ‘findUser’ operation
response = client.call(:find_user, message: { id: 42 })
client.call(:create_user, message: {name: ‘Jay’})
namespaces = {
“xmlns:open” => “https://brandedpromoapparel.com/WebServices/PurchaseOrder.svc",
“xmlns:pss” => “http://www.promostandards.org/WSDL/PurchaseOrder/1.0.0/SharedObjects/"
}
# create a client for the service:
client = Savon.client(
wsdl: “https://brandedpromoapparel.com/WebServices/WSDL/POService.wsdl",
endpoint: “https://brandedpromoapparel.com/WebServices/PurchaseOrder.svc",
env_namespace: :soap,
soap_version: 2,
namespaces: namespaces,
namespace_identifier: ‘ps’,
log: true,
log_level: :debug,
pretty_print_xml: true,
ssl_verify_mode: :none
)
If you want to check each of these options in detail, here sharing the Savon gem reference link, you can check here: https://www.savonrb.com/version2
Thanks for reading!
Hope it helps you with SOAP client implementation. For any queries, please reach out to us in the comment section.