Transforming request data
Last updated
Last updated
Sometimes there is need to change how what values and how are they being sent to API in for example quote or policy requests. Manifest request transformers can be used in cases like these.
Underneath is used to figure out how to transform values. It is used both for send_to_api
and value
.
Transformer interface:
ApiManifestJsonLogic interface:
JsonLogic can access variables (). We expose 3 state slices for both send_to_api
and value
JsonLogic: input
, flags
and quote
.
There are some cases that might not be that clear initially:
JsonLogic never returns undefined
value, instead it returns null
;
Cannot use Objects in value
, as uses Object structure too and it doesn't allow any custom key/property;
Instead use dot notation in path
to create nested structures like this:
output for this would be:
Let's say the API needs address
field, but user can tick prefill_address
tickbox, that would change address from previously filled in address fields
Webapp manifest configuration fragment:
In this example when Policy request is sent, it would look something like this:
And if there's already some data from field_definition
it gets merged with transformed data. In case with some other data it would look like this (let's imagine that there is address
and risk_address
in field_definition
too):
Let's say it's necessary to send value of person_count
to Quote API service conditionally. When user is set has_multiple_persons
to true
then send value, if has_multiple_persons
is false
then do not send person_count
.
Webapp manifest configuration fragment:
In this example when Quote request is sent, it would look something like this:
And if there's already some data from field_definition
it also gets merged same way like in previous example.
We can use string concatenation with :
We can do some mathematics with :