Skip to content

Documentation / @ember-data/request / index / default

Defined in: warp-drive-packages/core/declarations/request/-private/manager.d.ts:80

js
import RequestManager from '@ember-data/request';

A RequestManager provides a request/response flow in which configured handlers are successively given the opportunity to handle, modify, or pass-along a request.

ts
interface RequestManager {
  request<T>(req: RequestInfo): Future<T>;
}

For example:

ts
import RequestManager from '@ember-data/request';
import Fetch from '@ember-data/request/fetch';
import Auth from 'ember-simple-auth/ember-data-handler';
import Config from './config';

const { apiUrl } = Config;

// ... create manager
const manager = new RequestManager().use([Auth, Fetch]);

// ... execute a request
const response = await manager.request({
  url: `${apiUrl}/users`
});

Futures

The return value of manager.request is a Future, which allows access to limited information about the request while it is still pending and fulfills with the final state when the request completes.

A Future is cancellable via abort.

Handlers may optionally expose a ReadableStream to the Future for streaming data; however, when doing so the future should not resolve until the response stream is fully read.

ts
interface Future<T> extends Promise<StructuredDocument<T>> {
  abort(): void;

  async getStream(): ReadableStream | null;
}

StructuredDocuments

A Future resolves with a StructuredDataDocument or rejects with a StructuredErrorDocument.

ts
interface StructuredDataDocument<T> {
  request: ImmutableRequestInfo;
  response: ImmutableResponseInfo;
  content: T;
}
interface StructuredErrorDocument extends Error {
  request: ImmutableRequestInfo;
  response: ImmutableResponseInfo;
  error: string | object;
}
type StructuredDocument<T> = StructuredDataDocument<T> | StructuredErrorDocument;

RequestManager

Constructors

Constructor

ts
new default(options?): RequestManager;

Defined in: warp-drive-packages/core/declarations/request/-private/manager.d.ts:96

Parameters

options?

GenericCreateArgs

Returns

RequestManager

Properties

_deduped

ts
_deduped: Map<StableDocumentIdentifier, {
  priority: ManagedRequestPriority;
  promise: Promise<unknown>;
}>;

Defined in: warp-drive-packages/core/declarations/request/-private/manager.d.ts:92


_hasCacheHandler

ts
_hasCacheHandler: boolean;

Defined in: warp-drive-packages/core/declarations/request/-private/manager.d.ts:82

Methods

request()

ts
request<RT, T>(request): Future<RT>;

Defined in: warp-drive-packages/core/declarations/request/-private/manager.d.ts:132

Issue a Request.

Returns a Future that fulfills with a StructuredDocument

Type Parameters

RT

RT

T

T = unknown

Parameters

request

RequestInfo<RT, T>

Returns

Future<RT>


use()

ts
use(newHandlers): this;

Defined in: warp-drive-packages/core/declarations/request/-private/manager.d.ts:122

Register handler(s) to use when a request is issued.

Handlers will be invoked in the order they are registered. Each Handler is given the opportunity to handle the request, curry the request, or pass along a modified request.

Parameters

newHandlers

Handler[]

Returns

this


useCache()

ts
useCache(cacheHandler): this;

Defined in: warp-drive-packages/core/declarations/request/-private/manager.d.ts:108

Register a handler to use for primary cache intercept.

Only one such handler may exist. If using the same RequestManager as the Store instance the Store registers itself as a Cache handler.

Parameters

cacheHandler

CacheHandler & object

Returns

this


create()

ts
static create(options?): RequestManager;

Defined in: warp-drive-packages/core/declarations/request/-private/manager.d.ts:133

Parameters

options?

GenericCreateArgs

Returns

RequestManager

Released under the MIT License.