All services produce responses through their
self.response attribute. Unlike with requests, there are no protocol-specific sub-attributes.
The most general way to create a response, and one that is always possible, is to assign a string or Unicode object to
self.response.payload, e.g. as a result of manual serialization.
However, if using SimpleIO or if a channel's definition is JSON or XML, it is also possible for Zato to serialize objects directly, e.g. from dicts or SQLAlchemy objects.
All of the attributes and methods are always available to all services, regardless of the protocol they are invoked through though in the case of HTTP-specific ones, using them will be a no-op if the service is not invoked through HTTP.
|The main attribute via which responses are produced
|The object to which responses are assigned, i.e. this is the attribute through which a service's business data is returned, such as a JSON message
|(HTTP only) An integer status code such as 200 or 401 to return in response
|(HTTP only) Sets response's Content-Encoding header value
|(HTTP only) Sets response's Content-Type header value
|(HTTP only) A dictionary of header name/value to set in the response
Assiging to self.response.payload lets one return responses from services. It can be done in several ways:
By assigning a string/unicode object directly. This approach is always available:
If using SimpleIO, all the attributes can be assigned to as they appear in the SimpleIO definition, either one, as a dictionary or as a list. Serialization to JSON or XML will be done by Zato automatically, depending on service's channel definition.
Assigning attributes individually:
If using SimpleIO, it is also possible to assign SQLAlchemy objects directly from an SQL query: