Skip to content
MilvusNode SDK
Sections

Use the HttpClient for Milvus REST Requests

Markdown

Copy for agent

Use HttpClient to call Milvus REST v2 from runtimes with Fetch support, including HTTP-only edge and serverless platforms. Choose MilvusClient when your runtime supports gRPC and you need the SDK’s streaming or gRPC administration APIs.

Decision MilvusClient (gRPC) HttpClient (REST)
Protocol gRPC over HTTP/2 Milvus REST v2 over HTTP with JSON
Request field casing snake_case, such as collection_name camelCase, such as collectionName
Serverless and edge support Use in Node.js runtimes that support gRPC connections Use in Fetch-capable runtimes, including HTTP-only serverless and edge environments
Streaming and gRPC-only admin RPCs Supports replication and WAL streams, plus proxy and telemetry administration Supports REST management operations and returns JSON responses
Response and error handling Inspect error_code on a status or status.error_code on a result. Transport failures can reject. Inspect code where the REST response provides it. Non-2xx responses throw HttpError.
import { HttpClient } from '@zilliz/milvus2-sdk-node';
const client = new HttpClient({
endpoint: process.env.MILVUS_ENDPOINT ?? 'http://localhost:19530',
token: process.env.MILVUS_TOKEN,
});
const { code, data } = await client.listCollections({ dbName: 'default' });
if (code !== 0) throw new Error(`Milvus returned code ${code}`);
console.log(data);

Using HTTP Client in Serverless Environments

Section titled “Using HTTP Client in Serverless Environments”

For edge runtimes without Node.js built-ins, import HttpClient from @zilliz/milvus2-sdk-node/dist/milvus/HttpClient.js.

See the deployment guides for Cloudflare Workers, Vercel, and AWS Lambda.

See the constructor and per-request options for database defaults, timeouts, and custom Fetch implementations.

Catch HttpError for non-2xx HTTP responses. Inspect the Milvus code in successful HTTP responses.

Use environment variables for credentials and reuse the client across requests in long-running services. See Best Practices for deployment advice.

Use the SDK reference to look up TypeScript methods, or use the REST explorer to run a request directly.