The HTTP interface supports the use of ByteHouse on any platform in any programming language through the REST API. This article introduces how to connect to ByteHouse using the HTTP method.
Please ensure you have installed curl, see the official website for details.
You can connect to ByteHouse using the following command.
curl "https://<domain>:8123?user=bytehouse&password=${APItoken}"
Parameter | Configuration Key Points |
|---|---|
Configure the host information for ByteHouse. You can obtain the public or private domain name information in ByteHouse Console's tenant management>basic information>network information, format as follows:
Of which | |
user | Username for logging into the ByteHouse database, configured as bytehouse. |
password | Password for logging into the ByteHouse database, configured as ByteHouse's <API_Key>, which can be obtained in the **Tenant ManagementConnection Information ** section of the ByteHouse console. For more details, see Get API Key. |
You can connect to ByteHouse via HTTP and manage data. This section uses table t as an example, demonstrating how to create, write, query, and delete tables. Please replace the domain, api_token, and query statements according to your environment information and business needs in actual use.
echo 'CREATE TABLE t (a UInt8) ENGINE = 'CnchMergeTree' ORDER BY a' | curl 'https://<domain>:8123?user=bytehouse&password=<api_token>&' --data-binary @-
Support data insertion via INSERT search.
echo 'INSERT INTO t VALUES (1),(2),(3)' | curl 'https://<domain>:8123?user=bytehouse&password=<api_token>&' --data-binary @-
You can also separate the data from the query and send it.
echo '(4),(5),(6)' | curl 'https://<domain>:8123?user=bytehouse&password=<api_token>&query=INSERT%20INTO%20t%20VALUES' --data-binary @-
You can specify any data format. 'Values' format is the same as used when writing INSERT INTO t VALUES.
echo '(7),(8),(9)' | curl 'https://<domain>:8123?user=bytehouse&password=<api_token>&query=INSERT%20INTO%20t%20FORMAT%20Values' --data-binary @-
To insert data from a tab-separated dump, please specify the corresponding format.
echo -ne '10\n11\n12\n' | curl 'https://<domain>:8123?user=bytehouse&password=<api_token>&query=INSERT%20INTO%20t%20FORMAT%20TabSeparated' --data-binary @-
You can use the following commands to write to a CSV file.
curl "https://<domain>:8123?user=bytehouse&password=<api_token>&query=INSERT%20INTO%20t%20FORMAT%20CSV" --data-binary @data.csv
curl 'https://<domain>:8123/?user=bytehouse&password=<api_token>&query=SELECT%20a%20FROM%20t'
$ echo 'DROP TABLE t' | curl 'http://localhost:8123/' --data-binary @-
You can use format Pretty to optimize the style of your query results.
curl "https://gateway-rc.volc-boe.offline.bytehouse.cn:8123?query=select%20100%20format%20Pretty&user=bytehouse&password=${APItoken}"
You can also use format JSON; query results will be output in JSON format.
curl "https://gateway-rc.volc-boe.offline.bytehouse.cn:8123?query=select%20100%20format%20JSON&user=bytehouse&password=${APItoken}"