Enterprise Integration Zone is brought to you in partnership with:

Dariusz Suchojad has 12 years’ experience in enterprise architecture and software engineering with 8 years in EAI/ESB/SOA/BPM/SSO in telecommunications and banking. He feels equally well in dissecting proprietary protocols, developing systems of systems, talking businesses over and anything in between. Having spent far too many nights on putting out fires caused by the poor quality of solutions he had to use daily, he quit his job and spent almost 2 years on creating Zato, which is a Python-based ESB for SOA, cloud integrations and backend servers. Dariusz has posted 5 posts at DZone. You can read more from them at their website. View Full User Profile

Invoking JSON web services in Python with Zato ESB

08.27.2013
| 1996 views |
  • submit to reddit

This how-to shows what is needed to invoke JSON-based web services using Zato, a Python-based ESB for SOA, cloud integrations and backend services.

Show me the Code

This is the code needed:

# stdlib
from json import dumps

# Zato
from zato.server.service import Service

class MyService(Service):
    def handle(self):

        endpoint = self.outgoing.plain_http.get('Get Last Payment')

        request = dumps({'customer':123})
        response = endpoint.conn.post(self.cid, request)

        self.logger.info(response.text)

Read below for the whole story.

Swappable Endpoints

Everything in Zato is about reusability. No information is ever hard-coded, hence you don't access any particular addresses directly. Your own services use reusable outgoing connections that are created using the GUI, CLI, API or en masse from config files.

Thus, the code above is simply concerned with producing requests and handling responses but not with trivialities such as endpoint addresses.

You don't need to code security either - this is added automatically, if needed, by the platform.

For the curious one, HTTP endpoints are based on top of the excellent requests library and you can always access the underlying connection directly if it's needed.

Creating an Outgoing Connection in GUI

Filling out a form such as the one below is enough for an outgoing connection to a remote web service be created and propagated across all servers in a Zato cluster.

No restarts are needed. Everything is hot-reconfigured.

And that's all there is to it.

In the future, if you need to update an existing definition, this can be done with restarts by merely filling a form, with no code changes.

More Usage Examples

Browse the full API and more JSON usage examples here. The tutorial also makes use of JSON in part 2.

And by the way, Zato has support for XML, SOAP, CSV, other data formats, AMQP, FTP, JMS WebSphere MQ, Redis, job scheduling, SQL and ZeroMQ, too!

Published at DZone with permission of its author, Dariusz Suchojad. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)