> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apinizer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Creating API from Script with API Creator

> You can create REST APIs with a function-as-a-service approach with Script-2-API. You can write endpoint business logic in Javascript or Groovy language, process incoming message elements with script and send the result to the client

<CardGroup cols={2}>
  <Card title="Working Logic" icon="code">
    Elements of the incoming message (header, parameter, body) are processed with the selected script language and the result is sent to the client.
  </Card>

  <Card title="Read and Write Rules" icon="lock">
    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.
  </Card>
</CardGroup>

## Creating New Script-2-API

<Steps>
  <Step title="Go to Script-2-API Page from Menu">
    **Development → API Creator → Script-2-API** item is selected in the main menu.

    <img src="https://mintcdn.com/apinizer/ZcdqzXb0ZF1OeNQr/images/develop/api-proxy-olusturma/script-api-olusturma-ekrani.png?fit=max&auto=format&n=ZcdqzXb0ZF1OeNQr&q=85&s=7ec94b7cd368ade5eec00b9ab7a86970" alt="Script-2-API Creation Screen" width="1000" data-path="images/develop/api-proxy-olusturma/script-api-olusturma-ekrani.png" />
  </Step>

  <Step title="Create New API">
    The **+Create** button at the top right of the opened interface is clicked.
  </Step>

  <Step title="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.

    <img src="https://mintcdn.com/apinizer/WZR0m-u7Czbvjywf/images/develop/api-proxy-olusturma/script2api-new.png?fit=max&auto=format&n=WZR0m-u7Czbvjywf&q=85&s=4ceb185834c71b76e2af6155fd103196" alt="Filling API Information" width="1000" data-path="images/develop/api-proxy-olusturma/script2api-new.png" />
  </Step>

  <Step title="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.

    <img src="https://mintcdn.com/apinizer/WZR0m-u7Czbvjywf/images/develop/api-proxy-olusturma/script2api-neww.png?fit=max&auto=format&n=WZR0m-u7Czbvjywf&q=85&s=d1bfc411e81381670957c7d67c7a2feb" alt="Adding Endpoint" width="1000" data-path="images/develop/api-proxy-olusturma/script2api-neww.png" />
  </Step>
</Steps>

## Endpoint Creation

The following information is entered to define an *Endpoint*:

<img src="https://mintcdn.com/apinizer/ZcdqzXb0ZF1OeNQr/images/develop/api-proxy-olusturma/script-api-endpoint-olusturma.png?fit=max&auto=format&n=ZcdqzXb0ZF1OeNQr&q=85&s=fb6882de93a1bfc47c2f6982d699e9b2" alt="Endpoint Creation Screen" width="1000" data-path="images/develop/api-proxy-olusturma/script-api-endpoint-olusturma.png" />

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

<AccordionGroup>
  <Accordion title="Basic Information">
    <CardGroup cols={2}>
      <Card title="HTTP Method" icon="list">
        **Field:** HTTP Method

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

      <Card title="Name/URL" icon="tag">
        **Field:** Name/URL

        Endpoint access address. When API Proxy is created, the endpoint is accessed through this address.
      </Card>

      <Card title="Description" icon="file-lines">
        **Field:** Description

        Definition information of the API endpoint.
      </Card>
    </CardGroup>
  </Accordion>

  <Accordion title="Script Settings">
    <CardGroup cols={2}>
      <Card title="Script Type" icon="code">
        **Field:** Script Type

        Type of the Script to be written. Can be Javascript or Groovy.
      </Card>

      <Card title="Script" icon="code">
        **Field:** Script

        Information about the script to be executed.
      </Card>

      <Card title="Variables" icon="slider">
        **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.
      </Card>

      <Card title="Try Button" icon="play">
        **Field:** Try It

        Opens a new window to allow testing of the script to be executed.
      </Card>
    </CardGroup>
  </Accordion>
</AccordionGroup>

## Variables

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

<AccordionGroup>
  <Accordion title="Client → Apinizer (Request Data)">
    Variables used to access data coming from client to Apinizer:

    <CardGroup cols={2}>
      <Card title="Header" icon="heading">
        **Variable:** `requestHeaderMapFromClient`

        **Data Type:** `Map<String, String>`

        **Operation:** Read

        Used to read request headers.
      </Card>

      <Card title="Parameter (URL Parameter)" icon="slider">
        **Variable:** `requestUrlParamMapFromClient`

        **Data Type:** `Map<String, String>`

        **Operation:** Read

        Used to read URL parameters.
      </Card>

      <Card title="Body" icon="file-lines">
        **Variable:** `requestBodyTextFromClient`

        **Data Type:** `String`

        **Operation:** Read

        Used to read request body.
      </Card>

      <Card title="Message Information (Context)" icon="info">
        **Variable:** `contextValues`

        **Data Type:** `String`

        **Operation:** Read

        Used to access message information.
      </Card>

      <Card title="Custom Variable" icon="slider">
        **Variable:** `customVariableMap`

        **Data Type:** `Map<String, String>`

        **Operation:** Read, Write

        Used to read and write custom variables.
      </Card>
    </CardGroup>
  </Accordion>

  <Accordion title="Apinizer → Client (Response Data)">
    Variables used to create data to be sent from Apinizer to client:

    <CardGroup cols={2}>
      <Card title="Header" icon="heading">
        **Variable:** `responseHeaderMapToClient`

        **Data Type:** `Map<String, String>`

        **Operation:** Write

        Used to create response headers.
      </Card>

      <Card title="Body" icon="file-lines">
        **Variable:** `responseBodyTextToClient`

        **Data Type:** `String`

        **Operation:** Write

        Used to create response body.
      </Card>

      <Card title="Status Code" icon="code">
        **Variable:** `statusCodeToClient`

        **Data Type:** `Integer`

        **Operation:** Write

        Used to set HTTP status code.
      </Card>

      <Card title="Message Information (Context)" icon="info">
        **Variable:** `contextValues`

        **Data Type:** `String`

        **Operation:** Read

        Used to access message information.
      </Card>

      <Card title="Custom Variable" icon="slider">
        **Variable:** `customVariableMap`

        **Data Type:** `Map<String, String>`

        **Operation:** Read, Write

        Used to read and write custom variables.
      </Card>
    </CardGroup>
  </Accordion>
</AccordionGroup>

<Info>
  If script type is Groovy:

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

  Using these makes message processing quite easy.
</Info>

## 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.

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

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

<img src="https://mintcdn.com/apinizer/ZcdqzXb0ZF1OeNQr/images/develop/api-proxy-olusturma/script-api-proxy-olustur-butonu.png?fit=max&auto=format&n=ZcdqzXb0ZF1OeNQr&q=85&s=51527887f18491577a20741d62c6fc58" alt="Create Proxy Button" width="1000" data-path="images/develop/api-proxy-olusturma/script-api-proxy-olustur-butonu.png" />

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

<img src="https://mintcdn.com/apinizer/ZcdqzXb0ZF1OeNQr/images/develop/api-proxy-olusturma/script-api-proxy-olusturma-ekrani.png?fit=max&auto=format&n=ZcdqzXb0ZF1OeNQr&q=85&s=09855b6ebcfc3df5e8c77ed60e7b3f81" alt="API Proxy Creation Screen" width="1000" data-path="images/develop/api-proxy-olusturma/script-api-proxy-olusturma-ekrani.png" />

After this step, what can be done is the same as the API Proxy document. You can review the [API Proxy Creation](/en/develop/api-proxy-creation/api-proxy-creation) page for detailed information.

<Note>
  You can create multiple API Proxies for one Script-2-API.
</Note>

## 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 *Proxy*s created from this API. You can visit our Revision, Deployment, Redeployment, Undeployment pages for more detailed information on this topic.

<img src="https://mintcdn.com/apinizer/ZcdqzXb0ZF1OeNQr/images/develop/api-proxy-olusturma/script-api-proxy-yonetme.png?fit=max&auto=format&n=ZcdqzXb0ZF1OeNQr&q=85&s=c8a3dfa077bc398f6bdaf2a5ddadeca7" alt="Managing API Proxies" width="600" data-path="images/develop/api-proxy-olusturma/script-api-proxy-yonetme.png" />

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

<img src="https://mintcdn.com/apinizer/ZcdqzXb0ZF1OeNQr/images/develop/api-proxy-olusturma/script-api-deploy-onay.png?fit=max&auto=format&n=ZcdqzXb0ZF1OeNQr&q=85&s=87ded99822a966b31bce4b66dc3cbd0a" alt="Deployment Confirmation Screen" width="600" data-path="images/develop/api-proxy-olusturma/script-api-deploy-onay.png" />

<Info>
  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.
</Info>

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

<img src="https://mintcdn.com/apinizer/ZcdqzXb0ZF1OeNQr/images/develop/api-proxy-olusturma/script-api-yeniden-yukleme-bilgi.png?fit=max&auto=format&n=ZcdqzXb0ZF1OeNQr&q=85&s=794dcf80a391f50f77142313b78f03c5" alt="Redeployment Notification" width="500" data-path="images/develop/api-proxy-olusturma/script-api-yeniden-yukleme-bilgi.png" />

By saying **Redeploy**, changes are applied to API Proxies.

<img src="https://mintcdn.com/apinizer/ZcdqzXb0ZF1OeNQr/images/develop/api-proxy-olusturma/script-api-redeploy-onay.png?fit=max&auto=format&n=ZcdqzXb0ZF1OeNQr&q=85&s=426ef2d83ecd76753677b3ae36d77780" alt="Redeployment Confirmation Screen" width="600" data-path="images/develop/api-proxy-olusturma/script-api-redeploy-onay.png" />

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.

<img src="https://mintcdn.com/apinizer/ZcdqzXb0ZF1OeNQr/images/develop/api-proxy-olusturma/script-api-proxy-link.png?fit=max&auto=format&n=ZcdqzXb0ZF1OeNQr&q=85&s=4ad37edeeb50735ded2209b64f3ad7f7" alt="Going to API Proxy from Script-2-API Page" width="1000" data-path="images/develop/api-proxy-olusturma/script-api-proxy-link.png" />

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.

<img src="https://mintcdn.com/apinizer/ZcdqzXb0ZF1OeNQr/images/develop/api-proxy-olusturma/script-api-geri-link.png?fit=max&auto=format&n=ZcdqzXb0ZF1OeNQr&q=85&s=0882c36cf7fa36901d611feb2684ae87" alt="Going to Script-2-API from API Proxy Page" width="600" data-path="images/develop/api-proxy-olusturma/script-api-geri-link.png" />

## Script-2-API Deletion

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

<img src="https://mintcdn.com/apinizer/ZcdqzXb0ZF1OeNQr/images/develop/api-proxy-olusturma/script-api-silme-uyarisi.png?fit=max&auto=format&n=ZcdqzXb0ZF1OeNQr&q=85&s=d5b7c779595a7e79dfbf0111030af496" alt="Script-2-API Deletion Warning" width="500" data-path="images/develop/api-proxy-olusturma/script-api-silme-uyarisi.png" />
