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
- 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
- Request
-
GET http://localhost:8080/api/servers/server1/databases
- Response
-
[ "mydb", "mydb2", "stores_demo"]
- 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
- 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
- Request
-
DELETE http://localhost:8080/api/servers/server1/databases/mydb3
- Response
-
HTTP 200 OK