> ## 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 DB-2-API from MySQL Database

> Explains creating DB-2-API in Apinizer through MySQL database connection. Includes all steps from establishing database connection to defining endpoints, converting to API Proxy to testing.

The numbering in the diagram below corresponds to the **order of operations**.

* **API Client** makes a request to an **endpoint** in the **DB-2-API** on Apinizer.
* **Apinizer** sends this request to the **database**, and the query belonging to the relevant **endpoint** is executed on the database.
* The response to the relevant query from the **database** comes to **Apinizer**.
* **Apinizer sends the response to API Client**.

<img src="https://mintcdn.com/apinizer/HRgKWWQ8jUg_tEHu/images/tutorials/db-ana.png?fit=max&auto=format&n=HRgKWWQ8jUg_tEHu&q=85&s=2b3ec1776a9a0b18f71366f5d73f45b6" alt="Database connection page" width="1000" data-path="images/tutorials/db-ana.png" />

<Steps>
  <Step title="Establishing database connection">
    Defining MySQL database connection in Apinizer.
  </Step>

  <Step title="Creating endpoints">
    Defining endpoints for GET, POST, PUT, DELETE operations.
  </Step>

  <Step title="Converting to API Proxy">
    Converting DB-2-API to API Proxy format.
  </Step>

  <Step title="Testing">
    Testing the created endpoints.
  </Step>
</Steps>

## Establishing Database Connection

Select the **Database** expression under the **Connection Management** menu.

<img src="https://mintcdn.com/apinizer/HRgKWWQ8jUg_tEHu/images/tutorials/db1.png?fit=max&auto=format&n=HRgKWWQ8jUg_tEHu&q=85&s=3b437871a496f4f55c29bda9a56dba51" alt="Database connection page" width="200" data-path="images/tutorials/db1.png" />

<Info>
  Since no database connection has been made before, this page appears empty. Click the **Create** button in the top right corner.
</Info>

Start creating MySQL database connection.

<img src="https://mintcdn.com/apinizer/HRgKWWQ8jUg_tEHu/images/tutorials/db2.png?fit=max&auto=format&n=HRgKWWQ8jUg_tEHu&q=85&s=39e8bb84250fdd2d51b5c634c8cac228" alt="MySQL database connection creation page" width="1000" data-path="images/tutorials/db2.png" />

If the input fields on this page are examined;

* Write the name of the database you are connecting to with the **Name** field.
* A description is made for the connection to be created with the **Description** field.
* Select the type of connection to be created with **Database Type**.
* Write the address of the database to be connected to with the **JDBC URL** field. An example connection string is also in the input field.
* Enter the username required for the database to be connected to with the **Username** field, and write the password information to be entered during connection in the **Password** field.
* For information about other fields besides these fields, you can look at the [database connection](/en/integrations/connection-management/database) page.

<Tip>
  After entering the required database connection information, test the connection with the **Test Connection** button in the middle above, click the **Save And Deploy** button, and create the connection.
</Tip>

<img src="https://mintcdn.com/apinizer/HRgKWWQ8jUg_tEHu/images/tutorials/db3.png?fit=max&auto=format&n=HRgKWWQ8jUg_tEHu&q=85&s=cbb8577b59ffeb187fad07e942685555" alt="After database connection is saved" width="1000" data-path="images/tutorials/db3.png" />

The screenshot to be obtained after saving is shown in the image below.

<img src="https://mintcdn.com/apinizer/HRgKWWQ8jUg_tEHu/images/tutorials/db3-new.png?fit=max&auto=format&n=HRgKWWQ8jUg_tEHu&q=85&s=28c8f6563563f45b3db331e3d9d9c8d0" alt="After database connection is saved" width="1000" data-path="images/tutorials/db3-new.png" />

## Creating DB-2-API

After the database connection is established, proceed to the DB-2-API creation stage.

Select the **DB-2-API** option under the **API Creator** menu in the **Development** menu.

<img src="https://mintcdn.com/apinizer/HRgKWWQ8jUg_tEHu/images/tutorials/db4.png?fit=max&auto=format&n=HRgKWWQ8jUg_tEHu&q=85&s=31a45a71d1f4b664c8634fe66b213f35" alt="Empty page after DB-2-API option is selected" width="200" data-path="images/tutorials/db4.png" />

<Info>
  After selecting the **DB-2-API** option, an empty page appears on the screen. This is because no DB-2-API has been created before.
</Info>

Click the **Create** button in the top right corner on this screen to start creating DB-2-API.

<img src="https://mintcdn.com/apinizer/HRgKWWQ8jUg_tEHu/images/tutorials/db5.png?fit=max&auto=format&n=HRgKWWQ8jUg_tEHu&q=85&s=8d69c32be8ffdd1182c30584ee0aab75" alt="Page after clicking Create button" width="1000" data-path="images/tutorials/db5.png" />

The page that appears after clicking the **Create** button is shown below.

<img src="https://mintcdn.com/apinizer/HRgKWWQ8jUg_tEHu/images/tutorials/db5-new.png?fit=max&auto=format&n=HRgKWWQ8jUg_tEHu&q=85&s=b314bf01a92bcd44edc30c52a88744a2" alt="Page after clicking Create button" width="1000" data-path="images/tutorials/db5-new.png" />

On the page that appears after clicking the **Create** button:

* The **Name** field must give a name to the **DB-2-API**. This field cannot be left empty.
* A description can be added as desired.

After filling in the **Name** field, click the **Save and Next** button and proceed to the next step.

Now you can create DB-2-API on this page.

Click the **Add** button in the red rectangle to create the first endpoint.

<img src="https://mintcdn.com/apinizer/HRgKWWQ8jUg_tEHu/images/tutorials/db6-yeni.png?fit=max&auto=format&n=HRgKWWQ8jUg_tEHu&q=85&s=d4d72f79f8f47411d830bbcb382f13a7" alt="Creating endpoint by clicking Add button" width="1000" data-path="images/tutorials/db6-yeni.png" />

Fields on the endpoint creation screen:

* Select the methods **(GET,POST,DELETE,PUT, etc.)** of the endpoint to be created with the **HTTP Method** field.
* Enter the **name** of the endpoint in the **Name/URL** field.
* A **description** related to the endpoint can be added in the **Description** field.
* Select the database to be connected to with the **Connection Pool Definition** field.
* Specify how many seconds the created query will **timeout** with the **Timeout** field.
* Select **what type** the **SQL query** to be written will be created with the **Type of SQL Statement** expression.
* Enter the **SQL query** to be written in the **Enter SQL Statement** field.

<img src="https://mintcdn.com/apinizer/HRgKWWQ8jUg_tEHu/images/tutorials/db6.2.png?fit=max&auto=format&n=HRgKWWQ8jUg_tEHu&q=85&s=129f6dce870cd6c96d8b9239cab97aaf" alt="Fields for GET endpoint" width="1000" data-path="images/tutorials/db6.2.png" />

### GET Endpoint: /getSalariesByEmpNo

First, an endpoint named /getSalariesByEmpNo will be created.

For this endpoint to be usable, a parameter of **Query** type must be sent.

The fields to be used in this endpoint have been entered in the sections explained one by one above.

<img src="https://mintcdn.com/apinizer/HRgKWWQ8jUg_tEHu/images/tutorials/db7.png?fit=max&auto=format&n=HRgKWWQ8jUg_tEHu&q=85&s=fc1312d0c6886d2793b9d9e84c9815d1" alt="Fields for GET endpoint" width="1000" data-path="images/tutorials/db7.png" />

The image for the Query type parameter created is shown below.

<img src="https://mintcdn.com/apinizer/HRgKWWQ8jUg_tEHu/images/tutorials/db8.png?fit=max&auto=format&n=HRgKWWQ8jUg_tEHu&q=85&s=f16a48a099401a7a3350f47055f135ad" alt="Query type parameter" width="1000" data-path="images/tutorials/db8.png" />

Parameter properties:

* **Data Type**: integer
* **Repetition Type**: Single (because it contains a single field)
* **Parameter Type**: Query
* **Test Value**: Write the value to be tested to get an example response

Click the **Save** button to save the endpoint.

### PUT Endpoint: /updateDepartmentByDeptNo

The second endpoint to be created is the endpoint named /updateDepartmentByDeptNo.

For this, it is necessary to click the **Add** button in the red rectangle as seen in the image below.

<img src="https://mintcdn.com/apinizer/HRgKWWQ8jUg_tEHu/images/tutorials/db9.png?fit=max&auto=format&n=HRgKWWQ8jUg_tEHu&q=85&s=0b6bd16e0782f94315c6a91422daee4d" alt="Clicking Add button (for second endpoint)" width="1000" data-path="images/tutorials/db9.png" />

After clicking, the field where the endpoint can be created appears on the side.

The endpoint to be created takes a parameter of **Body** type.

<img src="https://mintcdn.com/apinizer/HRgKWWQ8jUg_tEHu/images/tutorials/db9.1.png?fit=max&auto=format&n=HRgKWWQ8jUg_tEHu&q=85&s=47861e14c8958ef20463a93456507d6e" alt="Clicking Add button (for second endpoint)" width="1000" data-path="images/tutorials/db9.1.png" />

The fields to be used in this endpoint have been entered in the sections explained one by one above.

The image for the Body type parameter created is shown below.

<img src="https://mintcdn.com/apinizer/HRgKWWQ8jUg_tEHu/images/tutorials/db10.png?fit=max&auto=format&n=HRgKWWQ8jUg_tEHu&q=85&s=bc73b9de3fdf33bfe1a20a1fb9f85697" alt="Fields for PUT endpoint" width="1000" data-path="images/tutorials/db10.png" />

Since this endpoint receives two different parameter values, the parameters are defined separately.

Since the created endpoint performs an update operation, the Body expression is selected as Parameter Type.

When the written SQL query is tested, the response shown in the image above is obtained.

### DELETE Endpoint: /deleteSalariesByEmpNo

The last endpoint to be created is the endpoint named /deleteSalariesByEmpNo.

To add this endpoint, click the **Add** button in the red rectangle in the image below and create the endpoint from the screen that opens on the right.

<img src="https://mintcdn.com/apinizer/HRgKWWQ8jUg_tEHu/images/tutorials/db12.png?fit=max&auto=format&n=HRgKWWQ8jUg_tEHu&q=85&s=312973e3b60d756c6c3d91b802eb49e6" alt="Clicking Add button (for third endpoint)" width="1000" data-path="images/tutorials/db12.png" />

After filling in the required fields, create the Query parameter that will be in the endpoint.

<img src="https://mintcdn.com/apinizer/HRgKWWQ8jUg_tEHu/images/tutorials/db13.png?fit=max&auto=format&n=HRgKWWQ8jUg_tEHu&q=85&s=a9effc5cdb6aa1b849e53d0bd1361c4f" alt="Query parameter for DELETE endpoint" width="1000" data-path="images/tutorials/db13.png" />

Test the SQL query written with the created Query parameter and obtain the example response shown in the image below.

<img src="https://mintcdn.com/apinizer/HRgKWWQ8jUg_tEHu/images/tutorials/db14.png?fit=max&auto=format&n=HRgKWWQ8jUg_tEHu&q=85&s=7998ae7918387128f5b1a42dd5064a8b" alt="DELETE endpoint test result" width="1000" data-path="images/tutorials/db14.png" />

This endpoint is saved and the final version of the DB-2-API to be created is shown in the image below.

The endpoints in the API are located in the rectangle on the left.

<img src="https://mintcdn.com/apinizer/HRgKWWQ8jUg_tEHu/images/tutorials/db15.png?fit=max&auto=format&n=HRgKWWQ8jUg_tEHu&q=85&s=5417498bef8133dac2d47756218aa6c7" alt="Final version of DB-2-API" width="1000" data-path="images/tutorials/db15.png" />

After all endpoints are created, click the **Create API Proxy** button in the top right corner.

## Creating API Proxy from DB-2-API

On this page:

* Give a name to the **API Proxy** to be created from DB-2-API in the **Name** field.
* Write the **/db2api** path expression in the **Relative Path** expression. This address will be the address where the API Proxy will be opened to the outside.

<img src="https://mintcdn.com/apinizer/HRgKWWQ8jUg_tEHu/images/tutorials/db16.png?fit=max&auto=format&n=HRgKWWQ8jUg_tEHu&q=85&s=2f24eeca812d349bf542bf08e567657e" alt="API Proxy creation page" width="1000" data-path="images/tutorials/db16.png" />

Click the **Save** button in the top right corner and save the proxy.

After the save operation is performed, you come to the page shown in the image below.

<img src="https://mintcdn.com/apinizer/HRgKWWQ8jUg_tEHu/images/tutorials/db17.png?fit=max&auto=format&n=HRgKWWQ8jUg_tEHu&q=85&s=fae2378d51622715f856008886351fe6" alt="Page after save operation" width="1000" data-path="images/tutorials/db17.png" />

## Testing the API Proxy

Here, click the **Deploy** button in the red rectangle above and in the image to **deploy the API Proxy**.

<img src="https://mintcdn.com/apinizer/HRgKWWQ8jUg_tEHu/images/tutorials/db18.png?fit=max&auto=format&n=HRgKWWQ8jUg_tEHu&q=85&s=19192fbb49afb67b6a8cc6121b5d72ff" alt="Deploy button" width="1000" data-path="images/tutorials/db18.png" />

After the proxy is deployed, the created endpoints are tested in order.

Select the **Develop** tab for test operations.

<Steps>
  <Step title="GET endpoint test">
    Select the endpoint named **/getSalariesByEmpNo** and click the **Test Endpoint** button.

    <img src="https://mintcdn.com/apinizer/HRgKWWQ8jUg_tEHu/images/tutorials/db19.png?fit=max&auto=format&n=HRgKWWQ8jUg_tEHu&q=85&s=a1deaf4e86dff7a144082127b2365a7c" alt="Develop tab" width="1000" data-path="images/tutorials/db19.png" />

    Enter the value **"10005"** as the **Query** parameter and obtain the response in the red rectangle.

    <img src="https://mintcdn.com/apinizer/HRgKWWQ8jUg_tEHu/images/tutorials/db20.png?fit=max&auto=format&n=HRgKWWQ8jUg_tEHu&q=85&s=7a57f45063665c7994d46e3837ed118a" alt="Develop tab" width="1000" data-path="images/tutorials/db20.png" />
  </Step>

  <Step title="PUT endpoint test">
    After testing this endpoint, select the second endpoint named **/updateDepartmentByDeptNo** for testing.

    Click the **Test Endpoint** button.

    <img src="https://mintcdn.com/apinizer/HRgKWWQ8jUg_tEHu/images/tutorials/db22.png?fit=max&auto=format&n=HRgKWWQ8jUg_tEHu&q=85&s=fbf7b42e7ca9d612bfe5f8f4ca47099d" alt="PUT endpoint test" width="1000" data-path="images/tutorials/db22.png" />

    Since this endpoint requests two pieces of data in the **Body**, they are given in **key/value** format.

    When the **Send** button is clicked, the response in the red rectangle is obtained as a response.

    <img src="https://mintcdn.com/apinizer/HRgKWWQ8jUg_tEHu/images/tutorials/db23.png?fit=max&auto=format&n=HRgKWWQ8jUg_tEHu&q=85&s=0bcd4deb4ff38e2aa8bd9f418312344a" alt="PUT endpoint test result" width="1000" data-path="images/tutorials/db23.png" />
  </Step>

  <Step title="DELETE endpoint test">
    Finally, select the endpoint named **/deleteSalariesByEmpNo** for testing.

    Click the **Test Endpoint** button.

    <img src="https://mintcdn.com/apinizer/HRgKWWQ8jUg_tEHu/images/tutorials/db24.png?fit=max&auto=format&n=HRgKWWQ8jUg_tEHu&q=85&s=558167919460d0c7eb131d2fd51a6bfb" alt="DELETE endpoint test" width="1000" data-path="images/tutorials/db24.png" />

    This endpoint takes a parameter of **Query** type. Enter the value **"10005"** and when you click the **Send** button, the response obtained is in the red rectangle.

    <img src="https://mintcdn.com/apinizer/HRgKWWQ8jUg_tEHu/images/tutorials/db25.png?fit=max&auto=format&n=HRgKWWQ8jUg_tEHu&q=85&s=a4726e99ff55f4ff9f5d1c5ba8a9ca61" alt="DELETE endpoint test result" width="1000" data-path="images/tutorials/db25.png" />
  </Step>
</Steps>
