Skip to content

@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()

ts
new AjaxProxy(options: AjaxProxyOptions): AjaxProxy

Defined in: src/typescript/lib/data/proxy/AjaxProxy.ts:51

Constructs an AjaxProxy from the given options.

Parameters

options

AjaxProxyOptions

The options object specifying the endpoint URL and HTTP options.

Returns

AjaxProxy

Overrides

Proxy.constructor

Methods

create()

ts
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

ModelRecord

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

Proxy.create


destroy()

ts
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

ModelRecord

The ModelRecord to delete on the server.

Returns

Promise<void>

A promise that resolves when the server confirms the deletion.

Overrides

Proxy.destroy


getLastTotalCount()

ts
getLastTotalCount(): undefined | number

Defined 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

Proxy.getLastTotalCount


read()

ts
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?

ReadParams

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

Proxy.read


update()

ts
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

ModelRecord

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.

Overrides

Proxy.update