Class

AxiosHttpAdapter

AxiosHttpAdapter(native, config, aliasopt)

Constructor

# new AxiosHttpAdapter(native, config, aliasopt)

Concrete implementation of HttpAdapter using Axios as the HTTP client. This adapter provides CRUD operations for RESTful APIs using Axios for HTTP requests.

Axios implementation of the HTTP adapter

sequenceDiagram participant Client participant AxiosHttpAdapter participant Axios participant API Client->>AxiosHttpAdapter: create(table, id, data) AxiosHttpAdapter->>AxiosHttpAdapter: url(table) AxiosHttpAdapter->>Axios: post(url, data) Axios->>API: HTTP POST Request API-->>Axios: Response Axios-->>AxiosHttpAdapter: Response Data AxiosHttpAdapter-->>Client: Created Resource Client->>AxiosHttpAdapter: read(table, id) AxiosHttpAdapter->>AxiosHttpAdapter: url(table, {id}) AxiosHttpAdapter->>Axios: get(url) Axios->>API: HTTP GET Request API-->>Axios: Response Axios-->>AxiosHttpAdapter: Response Data AxiosHttpAdapter-->>Client: Resource Data
Parameters:
Name Type Attributes Description
native Axios

The Axios instance

config HttpConfig

Configuration for the HTTP adapter

alias string <optional>

Optional alias for the adapter

View Source axios/axios.ts, line 51

Example
```typescript
import axios from 'axios';
import { AxiosHttpAdapter } from '@decaf-ts/for-http';

const config = { protocol: 'https', host: 'api.example.com' };
const adapter = new AxiosHttpAdapter(axios.create(), config);

// Use the adapter with a repository
const userRepo = adapter.getRepository(User);
const user = await userRepo.findById('123');
```

Classes

AxiosHttpAdapter

Concrete implementation of HttpAdapter using Axios as the HTTP client. This adapter provides CRUD operations for RESTful APIs using Axios for HTTP requests.

Methods

# async create(tableName, id, model) → {Promise.<Record.<string, any>>}

Implementation of the abstract create method from HttpAdapter. This method sends a POST request to the specified endpoint with the model data.

Creates a new resource via HTTP POST

Parameters:
Name Type Description
tableName string

The name of the table or endpoint

id string | number

The identifier for the resource (not used in URL for POST)

model Record.<string, any>

The data model to create

View Source axios/axios.ts, line 173

A promise that resolves with the created resource

Promise.<Record.<string, any>>

# async delete(tableName, id) → {Promise.<Record.<string, any>>}

Implementation of the abstract delete method from HttpAdapter. This method sends a DELETE request to the specified endpoint with the ID as a query parameter.

Deletes a resource by ID via HTTP DELETE

Parameters:
Name Type Description
tableName string

The name of the table or endpoint

id string | number | bigint

The identifier for the resource to delete

View Source axios/axios.ts, line 207

A promise that resolves with the deletion result

Promise.<Record.<string, any>>

# async read(tableName, id) → {Promise.<Record.<string, any>>}

Implementation of the abstract read method from HttpAdapter. This method sends a GET request to the specified endpoint with the ID as a query parameter.

Retrieves a resource by ID via HTTP GET

Parameters:
Name Type Description
tableName string

The name of the table or endpoint

id string | number | bigint

The identifier for the resource to retrieve

View Source axios/axios.ts, line 184

A promise that resolves with the retrieved resource

Promise.<Record.<string, any>>

# async request(details) → {Promise.<V>}

Implementation of the abstract request method from HttpAdapter. This method uses the Axios instance to send HTTP requests with the provided configuration.

Sends an HTTP request using Axios

Parameters:
Name Type Description
details AxiosRequestConfig

The Axios request configuration

View Source axios/axios.ts, line 161

A promise that resolves with the response data

Promise.<V>

# async update(tableName, id, model) → {Promise.<Record.<string, any>>}

Implementation of the abstract update method from HttpAdapter. This method sends a PUT request to the specified endpoint with the updated model data.

Updates an existing resource via HTTP PUT

Parameters:
Name Type Description
tableName string

The name of the table or endpoint

id string | number

The identifier for the resource (not used in URL for PUT)

model Record.<string, any>

The updated data model

View Source axios/axios.ts, line 196

A promise that resolves with the updated resource

Promise.<Record.<string, any>>

# static decoration()

Placeholder method for class decoration functionality. This method is currently empty but can be used for decorator-based configuration.

Static decoration method for the AxiosHttpAdapter class

View Source axios/axios.ts, line 214