Use the HttpClient for Milvus REST Requests
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.
HttpClient vs MilvusClient
Section titled “HttpClient vs MilvusClient”| 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. |
Creating HTTP Client
Section titled “Creating HTTP Client”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.
HTTP Client Configuration
Section titled “HTTP Client Configuration”See the constructor and per-request options for database defaults, timeouts, and custom Fetch implementations.
Error Handling
Section titled “Error Handling”Catch HttpError for non-2xx HTTP responses. Inspect the Milvus code in successful HTTP responses.
Best Practices
Section titled “Best Practices”Use environment variables for credentials and reuse the client across requests in long-running services. See Best Practices for deployment advice.
Next Steps
Section titled “Next Steps”Use the SDK reference to look up TypeScript methods, or use the REST explorer to run a request directly.
Operation shortcuts
Section titled “Operation shortcuts”-
Why HTTP Client for Serverless?
-
Vercel Example
-
Cloudflare Workers Example
-
AWS Lambda Example
-
Serverless Best Practices
-
Collection Operations
-
Create Collection
-
List Collections
-
Describe Collection
-
Drop Collection
-
Vector Operations
-
Insert Vectors
-
Search Vectors
-
Query Vectors
-
Delete Vectors
-
Index Operations
-
Create Index
-
Describe Index
-
List Indexes
-
Drop Index
-
Partition Operations
-
Create Partition
-
List Partitions
-
Drop Partition
-
Alias Operations
-
Create Alias
-
List Aliases
-
Drop Alias
-
Import Operations
-
Import Data
-
User Operations
-
Create User
-
List Users
-
Role Operations
-
Create Role
-
List Roles