With the Script Policy, header, parameter, body and error message contents in the messages can be processed with the selected script language.

The original version of the incoming request message (Client to API Proxy) and the original version of the returned response message (Backend API to API Proxy) cannot be changed, only reading can be made on this data. Both reading and modification can be done on the request to be sent to the Backend API (API Proxy to Backend API) and the response that will be returned to the client (API Proxy to Client).

The read and change operations to be made include the header, parameter and body parts of the message. Various keywords are used to access these fields on the script. These keywords vary according to the region to be accessed.

If we want to formulate keywords, we can express them as follows:

  • To access headers → <request|response>HeaderMap<From|To><Client|TargetAPI>
  • To access URL parameters → <request>UrlParamMap<From|To><Client|TargetAPI>
  • To access body → <request|response>BodyText<From|To><Client|TargetAPI>
  • To terminate the policy and return a customized error message → <request|response>ErrorMessage<From|To><Client|TargetAPI>

For example;

  • When the request from the client reaches Apinizer, that is, if it is want to access the body content of the original request, change the requestBodyTextFromClient variable,
  • If you want to access the headers of Apinizer when transmitting the incoming request to the Backend API, set the requestHeaderMapToTargetAPI variable,
  • If you want to access the headers of the response from the Backend API when it is sent to Apinizer, set the responseHeaderMapFromTargetAPI variable,
  • You can use the variable responseBodyTextToClient to access the body of the response that Apinizer returns to the client.

Variables in message regions

The variables that affect the policy added to the request line are shown in the table below:

Client → ApinizerData TypeOperationApinizer → Backend ApiData TypeOperation
HeaderrequestHeaderMapFromClientMap<String, String>OkumarequestHeaderMapToTargetAPIMap<String, String>

Okuma, Yazma

ParameterrequestUrlParamMapFromClientMap<String, String>OkumarequestUrlParamMapToTargetAPIMap<String, String>

Okuma, Yazma


Okuma, Yazma

Error Message---requestErrorMessageToTargetAPIStringYazma
Status Code---statusCodeToTargetAPIIntegerYazma

The variables that affect the policy added to the response line are shown in the table below:

Backend Api → ApinizerData TypeOperationApinizer → ClientData TypeOperation
BodyresponseHeaderMapFromTargetAPIMap<String, String>OkumaresponseHeaderMapToClientMap<String, String>

Okuma, Yazma


Okuma, Yazma

Error Message---responseErrorMessageToClientStringYazma
Status CodestatusCodeFromTargetAPIIntegerOkumastatusCodeToClientIntegerYazma

The Script Policy added to the request line cannot access variables in the response line.

The Script Policy added to the response Line can only read the variables in the request Line.

When one of the error message variables (requestErrorMessageToTargetAPI, responseErrorMessageToClient) is defined, the flow is interrupted.

That is, the request/response message is blocked.

When the request is blocked, instead of the Error Message Template, whatever is written to the value of this variable is returned to the client as an error message.

The image containing the policy settings is given below:

The policy fields are shown in the table below.

DescriptionAn optional description of the policy that may be useful for usage and management activities.
Script TypeThe type of script that will be written to the body; Javascript, Groovy
Script Body

Script code is written to operate on the request or response line.

It can be added to the body area by clicking on the links of the variables given according to the regions of the message.

Try it

Çalıştırılacak olan scriptin denemesinin yapılabilmesi için yeni bir pencere açılmasını sağlar.

The script to be run is tested. Trial operation is done on a dialog.

If the script language is Groovy;

They make the process of the message processing very easy.

You can visit the Policies page for the details of the Conditions and Error Message Customization panels.