Turso Quickstart (HTTP)
Get started with Turso using the libSQL remote protocol in a few simple steps.
In this HTTP quickstart we will learn how to:
- Obtain HTTP URL for a Turso database
- Create a database auth token
- Connect to a remote Turso database
- Execute a SQL using the libSQL remote protocol
Create HTTP Database URL
Using the Turso CLI or Platform API, fetch your database URL:
turso db show <database-name> --http-url
Append /v2/pipeline
to the URL and continue.
Create Database Auth Token
Using the Turso CLI or Platform API, create a new auth token for your database:
turso db tokens create <database-name>
Create JSON Request Payload
We’ll be sending the query using JSON, so let’s create a JSON payload that executes a SQL statement and closes the connection immediately:
{
"requests": [
{ "type": "execute", "stmt": { "sql": "SELECT * FROM users" } },
{ "type": "close" }
]
}
Make sure to update the stmt.sql
to select from a table you already have.
Bound parameter examples included on the Reference Page,
Execute HTTP Request
Depending on your language, you can use a HTTP client library to send the request to the URL you created as well as the Authorization
header set to the token you created, and the request body as JSON with your SQL statement.
You must append to the Base URL the actual pipeline URL that accepts requests — /v2/pipeline
.
If you need to use placeholders for values, you can do that:
The type
field within each arg corresponds to the column datatype and can be one of the following: null
, integer
, float
, text
, or blob
.
In JSON, the value
is a String
to avoid losing precision, because some
JSON implementations treat all numbers as 64-bit floats.
Was this page helpful?