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 Hrana over HTTP 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.


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.

const url = "https://[databaseName]-[organizationName]";
const authToken = "...";

fetch(url, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${authToken}`,
    "Content-Type": "application/json",
  body: JSON.stringify({
    requests: [
      { type: "execute", stmt: { sql: "SELECT * FROM users" } },
      { type: "close" },
  .then((res) => res.json())
  .then((data) => console.log(data))
  .catch((err) => console.log(err));