# new HttpAdapter(native, config, flavour, aliasopt)
Provides a base implementation for HTTP adapters with methods for CRUD operations, URL construction, and error handling. This class extends the core Adapter class and implements the necessary methods for HTTP communication. Concrete implementations must provide specific HTTP client functionality.
Abstract HTTP adapter for REST API interactions
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
native |
Y
|
The native HTTP client instance |
|
config |
HttpConfig
|
Configuration for the HTTP adapter |
|
flavour |
string
|
The adapter flavor identifier |
|
alias |
string
|
<optional> |
Optional alias for the adapter |
Example
```typescript
// Example implementation with Axios
class AxiosAdapter extends HttpAdapter<AxiosInstance, AxiosRequestConfig> {
constructor(config: HttpConfig) {
super(axios.create(), config, 'axios');
}
async request<V>(details: AxiosRequestConfig): Promise<V> {
const response = await this.native.request(details);
return response.data;
}
// Implement other abstract methods...
}
```
Classes
- HttpAdapter
Provides a base implementation for HTTP adapters with methods for CRUD operations, URL construction, and error handling. This class extends the core Adapter class and implements the necessary methods for HTTP communication. Concrete implementations must provide specific HTTP client functionality.
Methods
# Sequence(options) → {Promise.<Sequence>}
Method for creating a sequence for generating unique identifiers. This method is not supported by default in HTTP adapters and throws an UnsupportedError. Subclasses can override this method to provide implementation.
Creates a sequence
Parameters:
Name | Type | Description |
---|---|---|
options |
SequenceOptions
|
Options for creating the sequence |
Always throws as this method is not supported by default
UnsupportedError
A promise that resolves with the created sequence
Promise.<Sequence>
# Statement() → {Statement.<Q, M, any>}
Method for creating a statement for building and executing queries. This method is not supported by default in HTTP adapters and throws an UnsupportedError. Subclasses can override this method to provide implementation.
Creates a statement for querying
Always throws as this method is not supported by default
UnsupportedError
A statement object for building queries
Statement.<Q, M, any>
# abstract create(tableName, id, model, …args) → {Promise.<Record.<string, any>>}
Abstract method that must be implemented by subclasses to create a new resource via HTTP. This typically corresponds to a POST request.
Creates a new resource
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
tableName |
string
|
The name of the table or endpoint |
|
id |
string
|
number
|
The identifier for the resource |
|
model |
Record.<string, any>
|
The data model to create |
|
args |
Array.<any>
|
<repeatable> |
Additional arguments |
A promise that resolves with the created resource
Promise.<Record.<string, any>>
# abstract delete(tableName, id, …args) → {Promise.<Record.<string, any>>}
Abstract method that must be implemented by subclasses to delete a resource via HTTP. This typically corresponds to a DELETE request.
Deletes a resource by ID
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
tableName |
string
|
The name of the table or endpoint |
|
id |
string
|
number
|
bigint
|
The identifier for the resource to delete |
|
args |
Array.<any>
|
<repeatable> |
Additional arguments |
A promise that resolves with the deletion result
Promise.<Record.<string, any>>
# flags(operation, model, overrides) → {F}
Extends the base flags method to include HTTP-specific headers for operations. This method adds an empty headers object to the flags returned by the parent class.
Generates operation flags with HTTP headers
Parameters:
Name | Type | Description |
---|---|---|
operation |
OperationKeys.CREATE
|
OperationKeys.READ
|
OperationKeys.UPDATE
|
OperationKeys.DELETE
|
The operation type |
model |
Constructor.<M>
|
The model constructor |
overrides |
Partial.<F>
|
Optional flag overrides |
The flags object with headers
F
# async initialize(…args) → {Promise.<void>}
Placeholder method for adapter initialization. This method is currently a no-op but can be overridden by subclasses to perform initialization tasks.
Initializes the HTTP adapter
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
args |
Array.<any>
|
<repeatable> |
Initialization arguments |
A promise that resolves when initialization is complete
Promise.<void>
# parseCondition(condition) → {Q}
Method for parsing a condition object into a query format understood by the HTTP client. This method is not supported by default in HTTP adapters and throws an UnsupportedError. Subclasses can override this method to provide implementation.
Parses a condition into a query
Parameters:
Name | Type | Description |
---|---|---|
condition |
Condition.<any>
|
The condition to parse |
Always throws as this method is not supported by default
UnsupportedError
The parsed query
Q
# parseError(err) → {BaseError}
Processes errors that occur during HTTP operations and converts them to the appropriate BaseError type. Currently returns the error as-is, but can be extended to handle specific error messages differently.
Parses and converts errors to BaseError type
Parameters:
Name | Type | Description |
---|---|---|
err |
Error
|
The error to parse |
The parsed error as a BaseError
BaseError
# raw(rawInput, process, …args) → {Promise.<R>}
Method for executing raw queries directly with the HTTP client. This method is not supported by default in HTTP adapters and throws an UnsupportedError. Subclasses can override this method to provide implementation.
Executes a raw query
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
rawInput |
Q
|
The raw query input |
|
process |
boolean
|
Whether to process the result |
|
args |
Array.<any>
|
<repeatable> |
Additional arguments |
Always throws as this method is not supported by default
UnsupportedError
A promise that resolves with the query result
Promise.<R>
# abstract read(tableName, id, …args) → {Promise.<Record.<string, any>>}
Abstract method that must be implemented by subclasses to retrieve a resource via HTTP. This typically corresponds to a GET request.
Retrieves a resource by ID
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
tableName |
string
|
The name of the table or endpoint |
|
id |
string
|
number
|
bigint
|
The identifier for the resource |
|
args |
Array.<any>
|
<repeatable> |
Additional arguments |
A promise that resolves with the retrieved resource
Promise.<Record.<string, any>>
# repository() → {Constructor.<Repository.<M, Q, HttpAdapter.<Y, Q, F, C>>>}
Provides the RestService class as the repository implementation for this HTTP adapter. This method is used to create repository instances that work with this adapter type.
Returns the repository constructor for this adapter
The repository constructor
Constructor.<Repository.<M, Q, HttpAdapter.<Y, Q, F, C>>>
# abstract request(details) → {Promise.<V>}
Abstract method that must be implemented by subclasses to send HTTP requests using the native HTTP client. This is the core method for making API calls.
Sends an HTTP request
Parameters:
Name | Type | Description |
---|---|---|
details |
Q
|
The request details specific to the HTTP client |
A promise that resolves with the response data
Promise.<V>
# abstract update(tableName, id, model, …args) → {Promise.<Record.<string, any>>}
Abstract method that must be implemented by subclasses to update a resource via HTTP. This typically corresponds to a PUT or PATCH request.
Updates an existing resource
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
tableName |
string
|
The name of the table or endpoint |
|
id |
string
|
number
|
The identifier for the resource |
|
model |
Record.<string, any>
|
The updated data model |
|
args |
Array.<any>
|
<repeatable> |
Additional arguments |
A promise that resolves with the updated resource
Promise.<Record.<string, any>>
# protected url(tableName, queryParamsopt) → {string}
Builds a complete URL for API requests using the configured protocol and host, the specified table name, and optional query parameters. The method handles URL encoding.
Constructs a URL for API requests
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
tableName |
string
|
The name of the table or endpoint |
|
queryParams |
Record.<string, (string|number)>
|
<optional> |
Optional query parameters |
The encoded URL string
string