Class

HttpAdapter

HttpAdapter(native, config, flavour, aliasopt)

Constructor

# 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

View Source adapter.ts, line 6

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...
}
```

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

View Source adapter.ts, line 346

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

View Source adapter.ts, line 358

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

View Source adapter.ts, line 284

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

View Source adapter.ts, line 321

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

View Source adapter.ts, line 217

The flags object with headers

F

# 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

View Source adapter.ts, line 369

Always throws as this method is not supported by default

UnsupportedError

The parsed query

Q

# prepare(model, pk)

Converts a model instance into a format suitable for database storage, handling column mapping and separating transient properties

Prepares a model for persistence

Parameters:
Name Type Description
model M

The model instance to prepare

pk

The primary key property name

View Source adapter.ts, line 237

The prepared data

# 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

View Source adapter.ts, line 335

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

View Source adapter.ts, line 296

A promise that resolves with the retrieved resource

Promise.<Record.<string, any>>

# repository() → {Constructor.<Repository.<M, Q, HttpAdapter.<Y, Q, F, C>, 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

View Source adapter.ts, line 226

The repository constructor

Constructor.<Repository.<M, Q, HttpAdapter.<Y, Q, F, C>, 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

View Source adapter.ts, line 271

A promise that resolves with the response data

Promise.<V>

# revert(obj, clazz, pk, id) → {M}

Reconstructs a model instance from database data, handling column mapping and reattaching transient properties

Converts database data back into a model instance

Parameters:
Name Type Description
obj

The database record

clazz string | Constructor.<M>

The model class or name

pk

The primary key property name

id string | number | bigint

The primary key value

View Source adapter.ts, line 250

The reconstructed model instance

M

# 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

View Source adapter.ts, line 309

A promise that resolves with the updated resource

Promise.<Record.<string, any>>

# 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

View Source adapter.ts, line 260

The encoded URL string

string