The Script-2-API screen allows creating a REST API with the function-as-a-service approach. The business logics of the endpoints are written in Javascript or Groovy language.

The working logic of Script-2-API is as follows; The elements of the incoming message (header, parameter, body) are processed with the selected script language and the result is sent to the client.

The original version of the incoming request message cannot be changed, only reading can be made on this data. The response to the client is prepared in the script.

Creating a Script-2-API

The Development → API Creator → Script-2-API  path is followed through the main menu.

Click the Create button at the top right of the interface that opens.



The API creation work begins by filling in the fields below for the newly created API and clicking the Save and Next button at the top right

After the API is saved, endpoints are defined to the API. If there is no endpoint, the add button is pressed in the API to add it for the first time, if there is at least one, the add button in the endpoints section is pressed.


Endpoint Creation

To define an endpoint, the following information is entered:


The fields used for endpoint creation configuration are shown in the table below.

Field

Description

HTTP Method

HTTP Method is selected for REST APIs;

GET, POST, PUT, HEAD, OPTIONS, DELETE, PATCH, TRACE, ALL

Name/URL

Endpoint is the access address. When the API Proxy is created, the endpoint is accessed through this address.

Description

It is the optional definition of the API.

Script Type

The type of Script to be written. It could be Javascript or Groovy.

Variables

It is a list of read-only and write-only variables that can access the request and response pipeline. When the relevant variable is clicked, the variable is added to the cursor in the Script field.

Script

It is the script information to be executed.

Try It

It enables a new window to be opened so that the script to be run can be tested.

Variables

Various keywords are used to access the header, parameter and body parts of the message on the script for the reading and writing processes.

These areas and their types are summarized in the table below:


Client → Apinizer

Data Type

Operation

Apinizer → Client

Data Type

Operation

HeaderrequestHeaderMapFromClientMap<String, String>ReadingresponseHeaderMapToClientMap<String, String>

Writing

ParameterrequestUrlParamMapFromClientMap<String, String>Reading-Map<String, String>

-

BodyrequestBodyTextFromClientStringReadingresponseBodyTextToClientString

Writing

Status Code---statusCodeToClientIntegerWriting
Message InformationcontextValuesStringReadingcontextValuesStringReading
Custom VariablecustomVariableMapMap<String, String>Reading - WritingcustomVariableMapMap<String, String>Reading - Writing


If the script language is Groovy;

They make message processing very easy.


Creating API Proxy from Script-2-API

After the definitions of the API are finished, it is time to open this API as API Proxy.

To create an API Proxy from Script-2-API, the API created with Script-2-API must have at least one endpoint.

In order to create Script-2-API as API Proxy, click the Create Proxy button in the image below.


API Proxy is created by entering the required fields for API Proxy on the screen and clicking the Save button.


What can be done after this step is exactly the same as the API Proxy document. Click to go to the details.

You can create multiple API Proxies for a Script-2-API.

Deploy/Redeploy

To view and manage API Proxies in Mock API, click the Manage API Proxies link, and they are viewed and managed from the window that opens.

In the window that opens, Deploy/Undeploy and Redeploy API Proxies created with Mock API are done in this section. Revisions, Deploying, Redeploying, Undeploying

To deploy the API Proxy, click on the Manage API Proxies link and click on the deploy icon.


Confirmation is required after the above process. The information about the installation process is created and the Deploy button is clicked.


When a new endpoint is added to the Mock API or changes are made in the Script-2-API, all API Proxies created from this API must be redeployed in order for the change to take effect.

When you add a new Method/Endpoint or update an existing Method/Endpoint the following information will appear.


By clicking Reload, the changes are applied to the API Proxies.


Confirmation is required after the above process. Click the Redeploy button after creating the information about the reinstallation process.

 


From the Script-2-API page, click on the name of the API Proxy to go to API Proxy.


Similarly, to go to the Script-2-API page from the API Proxy page, click on the Mock API name in the API Proxy as follows.


Script-2-API Silme

When a Script-2-API is deleted, all API Proxies that depend on it are deleted first by Undeploy and then deleted.