JSON adapter

Invoking external endpoints using JSON is a common activity hence a dedicated JSON adapter, a utility service one's own services can subclass, makes the effort even easier.

Adapter services are intended to use either as pass-through proxy ones or as part of a deeper layer other services invoke, i.e. unless they are proxies, they will not be typically mounted on REST channels.

After subclassing zato.server.service.adapter.JSONAdapter it is possible to configure the service in a declarative manner, without a need to implement the usual self.handle method.

The two required attributes a adapter needs to configure are outconn and method indicating which outgoing REST connection to use and what the HTTP verb is.

A service such as the one below will use self.request.payload as input to be POST-ed to the outgoing connection called billing.eai9.

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

# Zato
from zato.server.service.adapter import JSONAdapter

class SetBillingInfo(JSONAdapter):
      """ Updates a customer's billing information.
      """
      outconn = 'billing.eai9'
      method = 'POST'

The following table lists all the configuration parameters.

NameRequiredDefault valueNotes
outconnYes(None)Name of an outgoing REST connection to use
methodYes(None)HTTP method to invoke the external resource with
params_to_qs--FalseWhether parameters from self.request.payload should form the query string or not
force_in_qs--[]A list of parameters that will always be placed in the query string even if params_to_qs is False
load_response--TrueWhether the response from the endpoint should be automatically deserialized into a Python object, such as a dictionary
params--{}A dictionary of additional parameters to use when building a request to the endpoint in addition to what has been obtained from self.request.payload
apply_params--APPLY_AFTER_REQUESTMust be either APPLY_AFTER_REQUEST or APPLY_BEFORE_REQEUST from zato.common.ADAPTER_PARAMS. If the former, self.params will take precedence over self.request.payload. The other way around if the latter.
raise_error_on--['4', '5']A list of prefixes of status codes returned from the endpoint which will make the adapter raise a zato.common.HTTPException instance.