In this scenario, it will be explained how to develop DB-2-API on Apinizer by providing only one database connection.

The numbering in the chart below belongs to the order of the transactions.

  1. API Client makes a request to an endpoint in the DB-2-API on Apinizer.
  2. Apinizer sends this request to the database, the query of the relevant endpoint is run on the database.
  3. The response of the relevant query from the database is sent to Apinizer.
  4. Apinizer sends the response to the API Client.


The script consists of several steps, if they are listed in order;

  1. Providing the connection of our MySQL database that we are using with Apinizer.
  2. Get the result of the endpoint named /getSalariesByEmpNo.
  3. Updating the record in the database with the endpoint named /updateDepartmentByDeptNo.
  4. Deleting the record in the database with the endpoint named /deleteSalariesByEmpNo.
  5. Deploying this created DB-2-API and testing all endpoints.

First, the database connection is made.

Performing Database Connection

For this, the Database statement under the Connection Management menu is selected.


Since no database connection has been made before, this page appears blank, click the Create button in the upper right corner.

MySQL database connection is started to be created.


If the input fields on this page are examined;

  • The name of the database you connect to is written in the Name field.
  • An explanation is given to the link to be created with the Description field.
  • The type of the database you connect to is chosen in the Database Type field.
  • With the JDBC URL field, the address of the database to be connected is written, the sample connection sentence is also included in the input field.
  • In the Username field, the user name that must be entered for the database to be connected, and the password that must be entered during the connection are entered in the Password field.
  • You can click on the link here for information about other areas other than these areas.
  • After the required database connection information is entered, the connection is tested with the "Test Connection" button in the middle above, the Save And Deploy button is clicked and the connection is created.


After saving, the screenshot to be obtained is in the image below.

Creating the DB-2-API

After the database connection is made, the DB-2-API creation phase is started.

For this step, the DB-2-API option under the API Creator menu in the Development menu is selected.


After the DB-2-API option is selected, a blank page appears on the screen.

This is because no DB-2-API has been created before.

On this screen, the DB-2-API starts to be created by clicking the Create button in the upper right corner.


The page that appears after clicking the Create button is as follows.


It is necessary to give a name to the DB-2-API from the Name field.

This field is a non-empty field.

An explanation can be added upon request.

After the Name field is filled, click the Save and Next button and proceed to the next step.

On this page you can now create DB-2-API.

The first endpoint is created by clicking the Add button in the red rectangle.


If the areas in the image below are examined;

  • The methods (GET, POST, DELETE, PUT etc.) of the endpoint to be created with the HTTP Method field are selected.
  • The name of the endpoint is entered in the Name/URL field.
  • A description of the endpoint can be added to the Description field.
  • The database to be connected with the Connection Pool Definition field is selected.
  • It is specified how many seconds after the timeout of the query created with the Timeout field.
  • With Type of SQL Statement, the type of SQL query to be written is selected.
  • In the Enter SQL Statement field, the SQL query to be written is entered.


After these field definitions are made, the endpoints in the test scenario are created sequentially.

First, the endpoint named /getSalariesByEmpNo will be created.

In order to use this endpoint, a "Query" type parameter must be sent.

 

The fields to be used in this endpoint are entered in the sections described above one by one.

The image of the created Query type parameter is given below.


If the properties of the parameter are examined;

  • It is seen that Data Type is integer and Repetition Type is Single.
  • This field is selected because the Query parameter we will use contains only one field.
  • Another data type of this field is Multiple.
  • There are Query and Body options as Parameter Type.
  • With the Test Value expression, the value to be tested is written and an example response is obtained as seen in the image.
  • The first created endpoint is saved by clicking the Save button.

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.


After clicking, the area that the endpoint can create is displayed on the side.

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


The fields to be used in this endpoint are entered in the sections described above one by one.

The image of the parameter in the Body type created is given below.


Since it takes two different parameter values in this endpoint, the parameters are defined separately.

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

When the written SQL query is also tested, the answer in the image above is obtained.

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 an endpoint on the screen that opens on the right.


After filling the required fields, the Query parameter to be included in the endpoint is created.


The SQL query written with the created Query parameter is tested and the sample response in the image below is obtained.


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

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

Click the Create API Proxy button in the upper right corner.

Creating API Proxy from DB-2-API

On this page, the Name field is given to the API Proxy to be created from DB-2-API.

Write /db2api path to Relative Path.

The address written here will be the address where API Proxy will open to the outside.

Click the Save button in the upper right corner and save the proxy.


After the saving process is completed, the page in the image below is reached.

Testing API Proxy

Here, API Proxy is deployed by pressing the Deploy button, which is located above and enclosed in the red rectangle in the image.

After the proxy is deployed, the endpoints created respectively are tested.

The Develop tab is selected for testing.


The endpoint named /getSalariesByEmpNo is selected and the Test Endpoint button is clicked.


The value of 10005 is entered as the query parameter and the response located in the red rectangle is obtained.


After testing this endpoint, the second endpoint named /updateDepartmentByDeptNo is selected for testing.

Click the Test Endpoint button.


Since this endpoint requires two data in the Body, they are given in key/value format.

When you click on the Send button, the response in the red rectangle is obtained.


Finally, the endpoint named /deleteSalariesByEmpNo is selected for testing.

Click the Test Endpoint button.


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