Skip to main content

Getting Started with DB2Rest

Let's discover DB2Rest in less than 10 minutes by running the Jar distribution.

Run On Premise / On Virtual Machines (VM)

In order to deploy DB2Rest on a laptop/PC/Mac, bare metal box or a VM on any cloud like Amazon EC2 or DigitalOcean Droplet, follow the steps below:

Pre-requisite

  • PostgreSQL/MySQL is installed and running.
  • employee table is created.

The script for creating the employee table is listed below:

PostgreSQL

CREATE TABLE employee (
id serial4 NOT NULL,
first_name varchar(50) NOT NULL,
last_name varchar(50) NOT NULL,
email varchar(255) NOT NULL,
created_on timestamp NOT NULL,
CONSTRAINT employee_email_key UNIQUE (email),
CONSTRAINT employee_pkey PRIMARY KEY (id)
);

MySQL

CREATE TABLE `employee` (
`emp_id` int unsigned NOT NULL AUTO_INCREMENT,
`first_name` varchar(100) NOT NULL,
`last_name` varchar(150) NOT NULL,
`create_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`is_active` tinyint(1) DEFAULT '1',
PRIMARY KEY (`emp_id`)
);

You can use your favorite SQL client to execute these scripts.

Minimum System Requirements for DB2REST

  • Java 21
  • 2-4 GB RAM/Memory.

DB2Rest needs Java Runtime 21+ to run. This is because it is compiled with Java 21 and makes uses of Java Virtual Thread feature for high scalability. With virtual thread DB2Rest can handle very high volume of requests even on a single machine.

Install JDK 21+

Download JDK 21 or above. There are many flavors of JDK available from different vendors like Oracle, AWS, OpenJDK.

Open JDK can be downloaded from here - https://jdk.java.net/21/. This article from https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/How-to-install-Java-21 provides a step by step guide to install OpenJDK 21 on Windows platform. For other operating system refer to this article https://www.freecodecamp.org/news/install-openjdk-free-java-multi-os-guide/ for guidance.

Oracle JDK 21 can be downloaded and installed for various operating systems by following the instructions here

Download DB2Rest

After successful installation of JDK 21+, the next step is to get download DB2Rest. DB2Rest is shipped as a single executable Java Archive or jar file. Hence, it is super easy to get up and running quickly.

The latest version of DB2Rest - V-1.1.2 can be downloaded from the link below:

Download Link

https://download.db2rest.com/db2rest-1.1.2.jar

Download Link for Legacy Oracle 9i

https://download.db2rest.com/db2rest-oracle9i-1.1.2.jar

Run DB2Rest.

Open terminal and set the following environment variables as shown below.

 export DB_USER=[DB_USER]
export DB_PASSWORD=[DB_PASSWORD]
export DB_URL=[DB_URL]

Replace the values for the following parameters:

Sl#Parameter NameDescriptionExample
1.DB_URLJDBC URL connection string- MySQL : jdbc:mysql://localhost:3306/sakila
- PostgreSQL : jdbc:postgresql://localhost:5432/sakila?currentSchema=public
2.DB_USERDatabase user
3.DB_PASSWORDDatabase password

Then execute the command below to start DB2Rest:

$ java -jar db2rest-1.1.2.jar

Once this command is executed, within a few seconds, DB2Rest is ready to service your data access requests.

Verify DB2Rest Installation

The actuator endpoint can be used to test the installation.


curl --request GET \
--url http://[IP_ADDRESS]:8080/actuator/health \
--header 'User-Agent: insomnia/8.6.1'


The actuator health check service in DB2Rest will return the following response:

HTTP/1.1 200
Content-Type: application/json
Transfer-Encoding: chunked

{
"status": "UP"
}

The status value of UP confirms that the service is up and running.

Test Drive DB2Rest

Insert Row


curl --request POST \
--url http://[IP_ADDRESS]:[PORT]/v1/rdbms/db/employee \
--header 'Content-Type: application/json' \
--header 'User-Agent: insomnia/8.6.1' \
--data '{
"first_name" : "Salman",
"last_name" : "Khan",
"email" : "sk@skfilms.com",
"created_on" : "2015-04-14T11:07:36.639Z"
}'


HTTP Response

{
"row": 1,
"keys": {
"id": 1
}
}

Read Row


curl --request GET \
--url http://[IP_ADDRESS]:[PORT]/v1/rdbms/db/employee \
--header 'User-Agent: insomnia/8.6.1'

HTTP Response

[
{
"id": 1,
"first_name": "Salman",
"last_name": "Khan",
"email": "sk@skfilms.com",
"created_on": "2015-04-14T11:07:36.639+00:00"
}
]

Finally, refer to the DB2Rest documentation for further learning and exploring API features.

For help, visit us on Discord or our GitHub Discussions