# 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
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 |
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 |
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 |
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 |
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 |
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 |
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