Documentation / @ember-data/request / index / default
Class: default
Defined in: warp-drive-packages/core/declarations/request/-private/manager.d.ts:96
Import
import { RequestManager } from '@warp-drive/core';
For complete usage guide see the RequestManager Documentation.
How It Works
interface RequestManager {
request<T>(req: RequestInfo): Future<T>;
}
A RequestManager provides a request/response flow in which configured handlers are successively given the opportunity to handle, modify, or pass-along a request.

For example:
import { RequestManager, Fetch } from '@warp-drive/core';
import { AutoCompress } from '@warp-drive/utilities/handlers';
import Auth from 'ember-simple-auth/handler';
// ... create manager
const manager = new RequestManager()
.use([Auth, new AutoCompress(), Fetch]);
import Config from './config';
const { apiUrl } = Config;
// ... 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.
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
.
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
Methods
request()
request<RT, T>(request): Future<RT>;
Defined in: warp-drive-packages/core/declarations/request/-private/manager.d.ts:148
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()
use(newHandlers): this;
Defined in: warp-drive-packages/core/declarations/request/-private/manager.d.ts:138
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()
useCache(cacheHandler): this;
Defined in: warp-drive-packages/core/declarations/request/-private/manager.d.ts:124
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
Constructors
Constructor
new default(options?): RequestManager;
Defined in: warp-drive-packages/core/declarations/request/-private/manager.d.ts:114
Parameters
options?
GenericCreateArgs
Returns
RequestManager