Ana içeriğe geç

Creating API from Script with API Creator

Working Logic

Elements of the incoming message (header, parameter, body) are processed with the selected script language and the result is sent to the client.

Read and Write Rules

Changes cannot be made to the original form of the incoming request message, only reading can be done on this data. The response to be returned to the client is prepared within the script.

Creating New Script-2-API

Go to Script-2-API Page from Menu

Development → API Creator → Script-2-API item is selected in the main menu.

Script-2-API Creation Screen
Create New API

The +Create button at the top right of the opened interface is clicked.

Fill API Information

Required fields for the new API to be created are filled and the →Save and Next button at the top right is clicked, starting the API creation process.

Filling API Information
Add Endpoint

After the API is saved, endpoint definition for the API begins. If there is no endpoint, press the add button inside the API for the first time to add, if there is at least one, press the add button that appears in the endpoints section.

Adding Endpoint

Endpoint Creation

The following information is entered to define an Endpoint:

Endpoint Creation Screen

Fields used for endpoint creation configuration are explained below, categorized:

Basic Information
HTTP Method

Field: HTTP Method

HTTP Method is selected for REST APIs: GET, POST, PUT, HEAD, OPTIONS, DELETE, PATCH, TRACE, ALL

Name/URL

Field: Name/URL

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

Description

Field: Description

Definition information of the API endpoint.

Script Settings
Script Type

Field: Script Type

Type of the Script to be written. Can be Javascript or Groovy.

Script

Field: Script

Information about the script to be executed.

Variables

Field: Variables

List of read-only and write-only variables that can be accessed in the request and response pipeline. When the relevant variable is clicked, the variable is added to the point where the cursor is located in the Script field.

Try Button

Field: Try It

Opens a new window to allow testing of the script to be executed.

Variables

Various keywords are used for access to message header, parameter, and body parts on script for read and write operations to be performed.

Client → Apinizer (Request Data)

Variables used to access data coming from client to Apinizer:

Header

Variable: requestHeaderMapFromClient

Data Type: Map<String, String>

Operation: Read

Used to read request headers.

Parameter (URL Parameter)

Variable: requestUrlParamMapFromClient

Data Type: Map<String, String>

Operation: Read

Used to read URL parameters.

Body

Variable: requestBodyTextFromClient

Data Type: String

Operation: Read

Used to read request body.

Message Information (Context)

Variable: contextValues

Data Type: String

Operation: Read

Used to access message information.

Custom Variable

Variable: customVariableMap

Data Type: Map<String, String>

Operation: Read, Write

Used to read and write custom variables.

Apinizer → Client (Response Data)

Variables used to create data to be sent from Apinizer to client:

Header

Variable: responseHeaderMapToClient

Data Type: Map<String, String>

Operation: Write

Used to create response headers.

Body

Variable: responseBodyTextToClient

Data Type: String

Operation: Write

Used to create response body.

Status Code

Variable: statusCodeToClient

Data Type: Integer

Operation: Write

Used to set HTTP status code.

Message Information (Context)

Variable: contextValues

Data Type: String

Operation: Read

Used to access message information.

Custom Variable

Variable: customVariableMap

Data Type: Map<String, String>

Operation: Read, Write

Used to read and write custom variables.

bilgi

If script type is Groovy:

  • JsonSlurper when message body is JSON
  • XMLSlurper when message body is XML

Using these makes message processing quite easy.

Creating API Proxy from Script-2-API

After the API's definitions are completed, it's time to open this API as an API Proxy.

bilgi

At least one endpoint of the API created with Script-2-API must exist to create an API Proxy from Script-2-API.

To open Script-2-API as an API Proxy for access, press the Create Proxy button shown in the following visual.

Create Proxy Button

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

API Proxy Creation Screen

After this step, what can be done is the same as the API Proxy document. You can review the API Proxy Creation page for detailed information.

not

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

Deploy/Redeploy

You can manage the deployment status of API Proxies created with Script-2-API from the API Proxies page or by selecting the relevant API on the Script-2-API page.

To manage from the Script-2-API page, use the window opened by clicking the Manage API Proxies link located at the top of the page. In the opened window, you can perform Deploy, Redeploy, and Undeploy operations for API Proxys created from this API. You can visit our Revision, Deployment, Redeployment, Undeployment pages for more detailed information on this topic.

Managing API Proxies

After the above operation, confirmation is required. Information about the deployment operation is created and the (Deploy) Deploy button is clicked.

Deployment Confirmation Screen
bilgi

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

When you add a new endpoint or update an existing endpoint, a notification like the following will appear.

Redeployment Notification

By saying Redeploy, changes are applied to API Proxies.

Redeployment Confirmation Screen

After the above operation, confirmation is required. Information about the redeployment operation is created and the (Redeploy) Redeploy button is clicked.

From the Script-2-API page, go to the API Proxy by clicking the API Proxy's name.

Going to API Proxy from Script-2-API Page

Similarly, to go to the Script-2-API page from the API Proxy page, go by clicking the Script-2-API name in the API Proxy as shown below.

Going to Script-2-API from API Proxy Page

Script-2-API Deletion

When a Script API is deleted, all API Proxies connected to it are first removed (undeploy) and then deleted.

Script-2-API Deletion Warning