Head over to the new chapter in the Zato documentation to find out how to integrate Django and Flask applications with Zato services.
The service it uses is a hypothetical yet fully functional one which looks up and caches user data by their IDs.
The integration effort is presented from the point of view of both libraries using self-contained ready-to-use projects living on GitHub.
Simply put - it contains everything you need to integrate Django or Flask with Zato :-)
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
# stdlib
from random import choice
# Zato
from zato.server.service import Service
# A set of first and last names to generate customer names from
first = ('Richard', 'Victoria', 'Sebastian', 'James', 'Hannah')
last = ('Ogden', 'Piper', 'Edmunds', 'Murray', 'Young')
# Redis key we store our cache under
CACHE_KEY = 'example:customer:by-id'
class GetCustomer(Service):
name = 'customer.get2'
def get_customer(self, cust_id):
# Assume in an actual service this would look up the data in a real DB
return '{} {}'.format(choice(first), choice(last))
def handle(self):
self.log_input()
# Customer ID received on input
cust_id = self.request.payload['cust_id']
# Do we have their name in cache?
name = self.kvdb.conn.hget(CACHE_KEY, cust_id)
# If not, we need to ask the backend and cache the response
if not name:
name = self.get_customer(cust_id)
self.kvdb.conn.hset(CACHE_KEY, cust_id, name)
# Produce the response for the calling application.
self.response.payload = {'name': name}
Django screenshots below:


