REST API Examples: Accessing your server and databases

This topic provides a tutorial on the REST APIs for acessing your server and database information.

In your REST configuration file, you define one or more OneDB database servers that the REST API can connect to. Each server must be given an alias for use within the REST API. You use the server alias in the REST URLs to run requests against that particular database server.

Througout the following examples, server1 serves as the alias to the OneDB database server as defined in the REST configuration file. These examples also use localhost:8080 as the host and port that the REST API server is running on.

Example 1: Get server information

To get information about your database server whose alias is "server1":
Request
GET http://localhost:8080/api/servers/server1
Response
{
    "alias": "server1",
    "host": "host1.mycompany.com",
    "port": 9088,
    "version": "HCL OneDB Server 1.0.1.0"
}

Example 2: List databases

To list the databases on a database server:
Request
GET http://localhost:8080/api/servers/server1/databases
Response
[ "mydb", "mydb2", "stores_demo"]

To include system databases in the list:
Request
GET http://localhost:8080/api/servers/server1/databases?includeSystem=true
Response
[ "mydb", "mydb2", "stores_demo", "sysadmin", "syscdr", "sysmaster", "sysuser"]

Example 3: Create a database

To create a new database, POST a JSON document describing the new database. A name is required. You can optionally also specify the dbspace name, the locale, and the loggingMode ("Unbuffered log", "Buffered log", "ANSI", or "None") for the new database.
Request
POST http://localhost:8080/api/servers/server1/databases
Request Body
{ "name": "mydb3", "loggingMode": "Unbuffered log" }
Response
{
    "name": "mydb3",
    "owner": "onedbsa",
    "created": {
        "$date": "2021-03-01T06:00:00Z"
    },
    "locale": "en_US.819",
    "loggingMode": "Unbuffered log"
}

Example 4: Drop a database

To drop the database named "mydb3":
Request
DELETE http://localhost:8080/api/servers/server1/databases/mydb3
Response
HTTP 200 OK