Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Neon · Const

HTTP driver

Neon’s HTTP driver uses the neon() function from @neondatabase/serverless to issue Postgres queries through HTTP fetch requests. It is designed for serverless and edge runtimes, especially for single queries and non-interactive transactions.

How it works

The HTTP driver uses the neon() function from @neondatabase/serverless. It returns a tagged-template query function that sends each query through fetch, avoiding a persistent connection and making it suitable for serverless and edge runtimes.

Syntax

neon(connectionString)

Parameters

NameTypeDescription
connectionStringstringNeon Postgres connection string, normally supplied from an environment variable.

Returns

A tagged-template query function for executing SQL over HTTP.

Key points

  • Each query is transmitted through an HTTP fetch request rather than a persistent database socket.
  • The HTTP entry point is the neon function provided by the serverless driver.
  • HTTP is optimized for low-latency execution of individual queries.

Common mistakes

  • Use the returned function as a tagged template; do not call it like a conventional query method or construct SQL by concatenating user input.
  • HTTP queries have a 64 MB limit for both the request and the response.

Example: Run a query over HTTP

import { neon } from '@neondatabase/serverless';

const sql = neon(process.env.DATABASE_URL!);
const users = await sql`SELECT id, name FROM users WHERE active = ${true}`;
console.log(users);

Creates the HTTP query function and executes a parameterized SQL query.

When to use it

One-shot queries

A serverless function executes one database operation per request.

Edge-runtime database access

An edge function runs SQL where a persistent TCP connection is unsuitable.

Non-interactive transactions

Several statements must run together without interactive session behavior.

Interview questions

QHow does Neon’s HTTP driver execute queries?

The HTTP interface is the neon() function from @neondatabase/serverless. It sends each query as an HTTP fetch request, which avoids maintaining a database connection and is optimized for serverless and edge runtimes.

Follow-up: When should WebSockets be preferred? Use the driver's Pool or Client when the application needs session state or interactive transactions.

QWhy is the HTTP driver's tagged-template interface useful?

neon() returns a query function designed to be used as a tagged template. Interpolated values are handled as query parameters, helping protect against SQL injection.

Follow-up: What is the corresponding limitation? The returned function is intended for tagged-template use rather than ordinary string-built SQL calls.

QWhen is the HTTP driver a good fit?

HTTP is the default choice for single queries and non-interactive transactions. Multiple statements can also be grouped with the driver's transaction function when they do not require interactive session behavior.

Follow-up: What constraint applies to HTTP payloads? Both the request and response are limited to 64 MB.

  • @neondatabase/serverless
  • neon()
  • WebSockets
  • Pool
  • Client
  • transaction()

Source: Neon serverless driver - Neon Docs. Checked 2026-10-16.