@jimka/typescript-ui / data / AjaxProxy
Class: AjaxProxy
Defined in: src/typescript/lib/data/proxy/AjaxProxy.ts:36
A proxy that communicates with a remote HTTP/REST endpoint using the Fetch API. Supports configurable HTTP methods and an optional root key for unwrapping responses.
Remarks
Update and destroy requests are sent to {url}/{id} where id is the record's primary key value. All four CRUD methods throw an Error when the server responds with a non-OK status code.
Extends
Constructors
new AjaxProxy()
new AjaxProxy(options: AjaxProxyOptions): AjaxProxyDefined in: src/typescript/lib/data/proxy/AjaxProxy.ts:51
Constructs an AjaxProxy from the given options.
Parameters
options
The options object specifying the endpoint URL and HTTP options.
Returns
Overrides
Methods
create()
create(record: ModelRecord): Promise<Record<string, any>>Defined in: src/typescript/lib/data/proxy/AjaxProxy.ts:163
Posts a new record to the server and returns the server response data.
Parameters
record
The new ModelRecord to send to the server.
Returns
Promise<Record<string, any>>
A promise that resolves to the server response object, unwrapped from root if configured.
Overrides
destroy()
destroy(record: ModelRecord): Promise<void>Defined in: src/typescript/lib/data/proxy/AjaxProxy.ts:210
Sends a DELETE request for the record to {url}/{id}.
Parameters
record
The ModelRecord to delete on the server.
Returns
Promise<void>
A promise that resolves when the server confirms the deletion.
Overrides
getLastTotalCount()
getLastTotalCount(): undefined | numberDefined in: src/typescript/lib/data/proxy/AjaxProxy.ts:151
Returns the total record count reported by the most recent paginated read.
Returns
undefined | number
The total value parsed from the last paginated response, or undefined if no paginated read has occurred or the server omitted it.
Overrides
read()
read(params?: ReadParams): Promise<any[]>Defined in: src/typescript/lib/data/proxy/AjaxProxy.ts:80
Fetches records from the configured URL, optionally with pagination.
Parameters
params?
Optional. Pagination parameters from the store. When provided, page and pageSize are appended as query-string parameters and the response is parsed as a { data, total } envelope.
Returns
Promise<any[]>
A promise that resolves to an array of raw data objects from the server.
Remarks
Unpaginated mode: when params is omitted, the response JSON is read as a top-level array, or unwrapped via root if configured. An Error is thrown for non-OK responses or unexpected response shapes.
Paginated mode: when params carries page or pageSize, the request URL is extended with ?page=N&pageSize=M. The response is expected to be { data: T[], total: number }. If root is configured, the envelope is read from json[root] first. The reported total is stored and exposed via getLastTotalCount.
Overrides
update()
update(record: ModelRecord): Promise<Record<string, any>>Defined in: src/typescript/lib/data/proxy/AjaxProxy.ts:187
Sends an update request for an existing record to {url}/{id} and returns the server response.
Parameters
record
The dirty ModelRecord to update on the server.
Returns
Promise<Record<string, any>>
A promise that resolves to the server response object, unwrapped from root if configured.