Tuesday, February 11, 2025
HomePythonChanging SOAP and WSDL into REST APIs

Changing SOAP and WSDL into REST APIs


Even when most of recent APIs right this moment are constructed round REST, there are nonetheless already current, manufacturing purposes and programs that expose their APIs utilizing SOAP and WSDL solely – in right this moment’s article we’re integrating with a SOAP service as a way to expose it as a REST interface to exterior purposes.

WSDL

WSDL is the language which describes how one can invoke SOAP-based purposes, utilizing what enter, below what deal with and what output to count on. Within the article, we’re utilizing a public endpoint whose WSDL you may obtain right here.

As soon as downloaded, import the WSDL right into a instrument resembling Enterprise Architect or Eclipse to browse its contents. You too can import it to SoapUI to invoke the identical service that we’re going to entry from Zato and Python in a while.

Zato Dashboard

Step one is to create a brand new outgoing SOAP connection in Zato web-admin – merely fill out the shape, pointing it to the situation of the WSDL useful resource that comprises the outline of the distant endpoint.

As soon as that is achieved, you’ll discover a sequence of entries within the Zato server log, confirming {that a} queue of connections to the SOAP endpoint has been created efficiently.

Python code

We are able to now writer the code wanted for the transformation of SOAP into JSON – for simplicity, we’re invoking just one particular SOAP service right here (LanguageISOCode) however in a full integration undertaking, it will be straightforward to automate the entire course of and have a single transformation service, translating JSON calls into SOAP and the opposite means round.

# -*- coding: utf-8 -*-

# Zato
from zato.server.service import Service

class SOAPTransformer(Service):
    identify = 'api.cleaning soap.transformer'

    class SimpleIO:
        enter = 'lang_name'
        output = 'lang_code'
        response_elem = None

    def deal with(self):

        # Identify of the SOAP connection pool to make use of
        conn_name = 'My SOAP Endpoint'

        # Receive a consumer from the queue ..
        with self.outgoing.cleaning soap.get(conn_name).conn.consumer() as consumer:

            # .. put together enter knowledge ..
            lang_name = self.request.enter.lang_name

            # .. invoke the SOAP service ..
            lang_code = consumer.service.LanguageISOCode(lang_name)

            # .. log the consequence obtained ..
            self.logger.data('SOAP response: `%s`', lang_code)

            # .. and return the consequence to our caller.
            self.response.payload.lang_code = lang_code

API channel

After deploying the service above, we are able to create a REST API channel for it.

Invoking the REST endpoint

Now, it’s doable to invoke the REST endpoint – let’s use curl to do exactly that:

WSDL reloading

We’re virtually achieved however there’s nonetheless one level to bear in mind – when a WSDL modifications, e.g. when a SOAP endpoint’s service modifies its enter or output, you could reload the WSDL in Zato in order to load within the latest updates.

You are able to do it in web-admin too – go to Connections -> SOAP and click on Reload WSDL, as under:

Now we’re actually by way of though we might very effectively go additional. For example, we are able to add a number of REST channels, deal with a number of SOAP backend endpoints or flip WSDL-based companies into OpenAPI-based ones. These are all legitimate topics however they’re left for future articles.

Extra assets

➤ Python API integration tutorial
What’s an integration platform?
Python Integration platform as a Service (iPaaS)
What’s an Enterprise Service Bus (ESB)? What’s SOA?
Open-source iPaaS in Python

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments