Request objects

Overview

All services always have access to the attributes that describe in a general way the request being handled. Additionally, protocol-specific attributes, such as self.request.http, cover details pertaining to information that is specific to a particular protocol.

Most commonly accessed attributes are:

AttributeDescription
self.request.inputUsed to access incoming data if data models are used
self.request.payloadUsed to access incoming data if data models are not used
self.request.raw_requestUsed to access incoming data in exactly the same format as it was received by the service, prior to any parsing or transformations

The chapter first details common attributes and then goes into particulars of each protocol-specific part.

Common attributes

Attributes listed in this section are available to all services, regardless of what kind of a channel they are invoked over, be it HTTP, AMQP, ZeroMQ, scheduler, SQL notifications or any other.

AttributeDescription
self.requestAlong with self.channel, one of the main attributes describing incoming messages
self.request.raw_requestInput message exactly as it was received, byte-for-byte, prior to any transformations or parsing attempts on Zato end
self.request.inputInput message after parsing it into a channel-specific data format. For JSON messages, this will be a Bunch object. Available only if data models are used.
self.request.payloadInput message after parsing it into a channel-specific data format. For JSON messages, this will be a dict object. Available even if data models are not used.
self.channelAlong with self.request, describes data and metadata about incoming messages. Unlike self.request, this attribute is the same for all requests coming through the same channel, i.e. it describes details of the channel itself rather than each individual message received.
self.channel.nameName of the channel the request was received through
self.channel.typeType of the channel - will be equal to one of the constants in zato.common.CHANNEL
self.chanAlias to self.channel
self.channel.securityDescribes a security definition attached to the channel, if any is at all
self.channel.security.nameName of the security definition
self.channel.security.usernameUsername used to invoke the channel, if applicable for a particular security type
self.channel.security.typeType of the security definition - will be equal to one of the constants in zato.common.SEC_DEF_TYPE
self.channel.secAlias to self.channel.security

HTTP-specific attributes

AttributeDescription
self.request.httpThe attribute to use to access HTTP-specific information
self.request.http.methodHTTP method used to invoke the service
self.request.http.GETAll GET parameters as a Bunch object, each value is either an exact one received or a list of values if there was more than one for a given key
self.request.http.POSTAll POST parameters as a Bunch object, each value is either an exact one received or a list of values if there was more than one for a given key. Available only if there is no data format set for channel.
self.request.http.pathURL path that the request was received through, e.g. /customer/123 in "https://localhost:17010/customer/123"; the value does not include a query string
self.request.http.paramsA dict-like object with a concatenation of query string and path parameters. Available even if data models are not used.
self.wsgi_environWhile not belonging directly to self.request.http, each service can always have access to the full WSGI dictionary of data and metadata about the request

AMQP-specific attributes

AttributeDescription
self.request.amqpThe attribute to use to access AMQP-specific information
self.request.amqp.msgLow-level object representing the incoming message
self.request.amqp.ack()Used by services to acknowledge the reception of a message
self.request.amqp.reject()Used by services to reject a message back to the AMQP broker

IBM MQ-specific attributes

AttributeDescriptionMQMD equivalent
self.request.ibm_mqThe attribute to use to access IBM MQ-specific information---
self.request.ibm_mq.msg_idMessage IDMsgId
self.request.ibm_mq.correlation_idCorrelation IDCorrelId
self.request.ibm_mq.timestampTimestamp of when the message was created---
self.request.ibm_mq.put_dateDate part of when the message was enqueuedPutDate
self.request.ibm_mq.put_timeTime part of when the message was enqueuedPutTime
self.request.ibm_mq.reply_toTo what queue responses should be sent, if any are expectedReplyToQ
self.request.ibm_mq.mqmdThe whole MQMD header as it was received from MQMQMD
self.request.ibm_mq.dataThe same as self.request.raw_request - added for convenience---

More information

  • Consult the dedicated chapter with programming examples for more details.
  • To learn more about data models, click here
  • Visit this chapter to read more about response objects