REST and JSON Sample data


This section of the documentation provides some samples of the JSON responses from the BearDB REST Server.

REST Server JSON Response


Every REST request (GET, POST, etc.) will receive a standard response in JSON format from the BearDB REST server. The response is intended to relay the results of sql queries, any database errors, and any informational messages from the database engine.

A standard JSON response is structured as follows:
{
  "result": {
    "data": [],
    "responseMessage": "",
    "error": {
      "hasError": "false",
      "errorDetail": ""
    }
  }
}


The JSON response can be described as follows:

The response from any BearDB REST request is always a JSON result object, which will always have three child JSON objects;

  • The data array,
  • The responseMessage value,
  • The error object which indicates if an error occurred and what the error detail was.

NOTE: This response message structure will never vary and will not be changed in future releases.

JSON Reponse Samples


This is a sample of a SQL Query which returns 2 rows.

Request:
GET /beardb/rest/table/query?sql=Select%20*%20from%20testTable1

SQL from Request:
SELECT * FROM testTable1

Response JSON:
{
  "result":
  {
    "data": [
    {
      "testTable1.column1": "A value",
      "testTable1.column2": "Another value",
      "testTable1.column3": " 44",
      "testTable1.column4": "61"
    },
    {
      "testTable1.column1": "test insert one",
      "testTable1.column2": "test update two",
      "testTable1.column3": " 98324",
      "testTable1.column4": "123"
    } ]
    "responseMessage": "2 Rows.",
    "error": {
      "hasError": "false",
      "errorDetail": ""
    }
  }
}


This is a sample of a SQL Query which returns no rows.

Request:
GET /beardb/rest/table/query?sql=Select%20*%20from%20testTable1%20where%20column4%20%gt%2060

SQL from Request:
SELECT * FROM testTable1 WHERE column4 > 60

Response JSON:
{
  "result":
  {
    "data": []
    "responseMessage": "Query returned no results",
    "error": {
      "hasError": "false",
      "errorDetail": ""
    }
  }
}


This is a sample of a SQL Query which generates an error.

Request:
GET /beardb/rest/table/query?sql=Select%20*%20from%20testTableFoo%20where%20column4%20%gt%2060

SQL from Request:
SELECT * FROM testTableFoo WHERE column4 > 60

Response JSON:
{
  "result":
  {
    "data": []
    "responseMessage": "",
    "error": {
      "hasError": "true",
      "errorDetail": "The table testTableFoo does not exist"
    }
  }
}


This is a sample of a SQL INSERT.

Request:
POST /beardb/rest/table/testTable1?column1=col1%20value%20from%20REST&column2=col2%20REST%20value&column3=git&column4=22

SQL from Request:
INSERT INTO testTable1 (column1,column2,column3,column4)
VALUES ('col1 value from REST','col2 REST value','git',22)


Response JSON:
{
  "result":
  {
    "data": []
    "responseMessage": "Insert OK",
    "error": {
      "hasError": "false",
      "errorDetail": ""
    }
  }
}