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 25

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 526

Always throws as this method is not supported by default

UnsupportedError

A promise that resolves with the created sequence

Promise.<Sequence>

# Statement(overridesopt) → {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

Parameters:
Name Type Attributes Description
overrides Partial.<AdapterFlags> <optional>

View Source adapter.ts, line 539

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 464

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 501

A promise that resolves with the deletion result

Promise.<Record.<string, any>>

# async protected flags(operation, model, overrides, …args) → {Promise.<FlagsOf.<C>>}

Extends the base flags method to ensure HTTP headers exist on the flags payload.

Generates operation flags with HTTP headers

Parameters:
Name Type Attributes Description
operation OperationKeys | string

The type of operation being performed

model Constructor | Array.<Constructor>

The target model constructor(s)

overrides Partial.<FlagsOf.<C>>

Optional flag overrides

args Array.<any> <repeatable>

Additional arguments forwarded to the base implementation

View Source adapter.ts, line 366

The flags object with headers

Promise.<FlagsOf.<C>>

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

Always throws as this method is not supported by default

UnsupportedError

The parsed query

Q

# prepare(model, pk, args)

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

args

View Source adapter.ts, line 387

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 515

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 476

A promise that resolves with the retrieved resource

Promise.<Record.<string, any>>

# repository() → {Constructor.<R>}

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 375

The repository constructor

Constructor.<R>

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

The request details specific to the HTTP client

View Source adapter.ts, line 451

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 400

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 489

A promise that resolves with the updated resource

Promise.<Record.<string, any>>

# url(tableName, pathParamsopt, 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 | Constructor

The name of the table or endpoint

pathParams Array.<string> <optional>

Optional query parameters

queryParams Record.<string, (string|number)> <optional>

Optional query parameters

View Source adapter.ts, line 440

The encoded URL string

string