Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion packages/js-client-rest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,20 @@ try {

## Support

The REST implementation relies on the native [fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API), which is available in Deno and Node.js (starting on v18.0.0 without experimental flag). The Deno implementation [supports HTTP/2](https://deno.com/blog/every-web-api-in-deno#fetch-request-response-and-headers) whereas Node.js is still lagging on the spec and provide only HTTP 1.1 support (this is due to the fact that under the hood Node.js still relies on [undici](https://github.com/nodejs/undici)).
The REST implementation relies on the native [fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API), which is available in Deno and Node.js (starting on v18.0.0 without experimental flag). This package does not install its own fetch implementation or dispatcher layer, so transport behavior is delegated to the host runtime.
Comment thread
Inv1x marked this conversation as resolved.

If you need custom transport behavior, you can inject your own `fetch` implementation when constructing the client:

```ts
import {QdrantClient} from '@qdrant/js-client-rest';

const client = new QdrantClient({
url: 'http://localhost:6333',
fetch: globalThis.fetch,
});
```

This also allows advanced Node.js setups to keep using user-managed transport tooling such as `undici` without making it a dependency of this package.

## Releases

Expand Down
3 changes: 1 addition & 2 deletions packages/js-client-rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@
"openapi_schema_remote": "https://raw.githubusercontent.com/qdrant/qdrant/dev/docs/redoc/master/openapi.json"
},
"dependencies": {
"@qdrant/openapi-typescript-fetch": "1.2.6",
"undici": "^6.23.0"
"@qdrant/openapi-typescript-fetch": "1.2.6"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^24.1.0",
Expand Down
21 changes: 7 additions & 14 deletions packages/js-client-rest/src/api-client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {ApiError, Fetcher, Middleware} from '@qdrant/openapi-typescript-fetch';
import {ApiError, Middleware} from '@qdrant/openapi-typescript-fetch';
import {paths} from './openapi/generated_schema.js';
import {createDispatcher} from './dispatcher.js';
import {createFetcher} from './fetcher.js';
import {
QdrantClientResourceExhaustedError,
QdrantClientTimeoutError,
Expand All @@ -10,7 +10,7 @@ import {RestArgs} from './types.js';
import {createClientApi} from './openapi/generated_api_client.js';
import {ClientApi} from './openapi/generated_client_type.js';

export type Client = ReturnType<typeof Fetcher.for<paths>>;
export type Client = ReturnType<typeof createFetcher<paths>>;

export function createApis(baseUrl: string, args: RestArgs): ClientApi {
const client = createClient(baseUrl, args);
Expand All @@ -19,7 +19,7 @@ export function createApis(baseUrl: string, args: RestArgs): ClientApi {

export type OpenApiClient = ReturnType<typeof createApis>;

export function createClient(baseUrl: string, {headers, timeout, connections}: RestArgs): Client {
export function createClient(baseUrl: string, {headers, timeout, fetch}: RestArgs): Client {
const use: Middleware[] = [];
if (Number.isFinite(timeout)) {
use.push(async (url, init, next) => {
Expand Down Expand Up @@ -48,7 +48,7 @@ export function createClient(baseUrl: string, {headers, timeout, connections}: R
}
} catch (error) {
if (error instanceof ApiError && error.status === 429) {
const retryAfterHeader = error.headers.get('retry-after')?.[0];
const retryAfterHeader = error.headers.get('retry-after');
if (retryAfterHeader) {
throw new QdrantClientResourceExhaustedError(error.message, retryAfterHeader);
}
Expand All @@ -59,20 +59,13 @@ export function createClient(baseUrl: string, {headers, timeout, connections}: R
throw QdrantClientUnexpectedResponseError.forResponse(response);
});

const client = Fetcher.for<paths>();
// Configure client with 'undici' agent which is used in Node 18+
const client = createFetcher<paths>();
client.configure({
baseUrl,
init: {
headers,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
dispatcher:
typeof process !== 'undefined' &&
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
process.versions?.node
? createDispatcher(connections)
: undefined,
},
fetch,
use,
});
Comment thread
Inv1x marked this conversation as resolved.

Expand Down
23 changes: 0 additions & 23 deletions packages/js-client-rest/src/dispatcher.ts

This file was deleted.

Loading