Important
The SingleStore 9.1 release candidate (RC) gives you the opportunity to preview, evaluate, and provide feedback on new and upcoming features prior to their general availability. In the interim, SingleStore 9.0 is recommended for production workloads, which can later be upgraded to SingleStore 9.1.
Enable the Data API
On this page
SingleStore’s Data API is accessible via a built-in HTTP server.
Enable the Data API Service
Step 1: Enable the WebSocket Proxy
To enable the WebSocket proxy on the required nodes, you can use SingleStore Toolbox commands on a host where SingleStore Toolbox is installed and configured.
Before enabling WebSocket proxy, you need to obtain the MemSQL ID of the nodes for which you want to set the https_ or the http_ variable.MemSQL ID of all aggregator nodes.
sdb-admin list-nodes --role Master -q
Then use sdb-admin update config to set either the https_ or the http_ variable to any free port available and specify the MemSQL ID obtained for the aggregator nodes in the previous command.
For HTTPS:
sdb-admin update-config --memsql-id <nodeID> --set-global --key https_proxy_port --value <port>
For HTTP:
sdb-admin update-config --memsql-id <nodeID> --set-global --key http_proxy_port --value <port>
Note that https_ and http_ variables are mutually exclusive and the proxy will fail to start if both are set.https_ variable requires SSL to be enabled.
Step 2: Enable the API Endpoints
To make the API endpoints accessible on the HTTP server, run the following SingleStore Toolbox command.
sdb-admin update-config --memsql-id <nodeID> --set-global --key "http_api" --value "ON"
If the server is already running when you update the configuration, run the following command at the SingleStore command-line for the changes to take effect.
RESTART PROXY;
Important
-
The variables used for enabling the Data API must be configured on individual nodes.
SingleStore recommends enabling the Data API on every aggregator node in the cluster. -
SingleStore recommends using
sdb-admin update-configto set the variables involved in Data API configuration to make sure the variable values persist through server restart.This command, when used with the --set-globalflag, allows the variable values to take effect immediately (assuming the node is running) in addition to when the node starts.For more information, refer to the sdb-admin update-config. -
SingleStore recommends configuring the
https_or theproxy_ port http_variable to the same value across the cluster.proxy_ port -
The Data API should NOT be enabled on leaf nodes.
Optimize the Data API Configuration
After enabling the API, you can tweak the following connection-related settings for optimum performance of the database.
-
Use the
http_to limit the maximum impact of the HTTP server on the database server by limiting the maximum number of connections per user.api_ pool_ capacity -
Use the
http_variable to specify the maximum number of connections that can be open in each pool at any point in time.api_ pool_ max_ idle This setting helps reduce latency by holding database connections open.
For more information, refer to Non-Sync Variables List.
Test the Data API
Call the GET /ping API request to verify that the HTTP service is running and connectable.GET request to the /ping endpoint with no parameters:
curl https://localhost:8080/ping
If the Data API service is available and is able to respond to requests, you will receive the following response along with a 200 OK status code, indicating a successful HTTP response.
ping
If an error occurs, you will receive one of the HTTP response status codes, along with the error description in the response body.
The GET /ping request can only verify whether the HTTP service is running and connectable./exec and /query endpoints.
The following cURL command makes a POST API request to the /query/rows endpoint.root:password in the HTTP request with your SingleStore username:password string.
curl -H "Content-Type: application/json" --data '{"sql": "select 1+1"}' https://root:password@localhost:8080/api/v2/query/rows
If the API call is successful, you should see the following results along with a 200 OK status code.
{"results":[{"rows":[{"1+1":2}]}]}
If an error occurs, you will receive one of the HTTP response status codes, along with the error description in the response body.
If you format the JSON output with a formatting tool, the results appear as follows.
{"results": [{"rows": [{"1+1": 2}]}]}
Note: The GET /ping request should be used in automated health checks./exec and /query endpoints.
Last modified: July 18, 2024