llms.txt@packages/api · git:20260616.363929e · 2026-06-16 · sha256 0f68a70d5317a54a

llms.txt@packages/api git:20260616.363929eA

Immutable. This exact content never changes and is served at /api/v1/blob/0f68a70d5317a54a.

# @gears-frontx/api

> API communication protocols and service registry for FrontX SDK. Supports REST, SSE, and mock protocols.

Part of the FrontX SDK Layer (L1) - can be used independently without other @gears-frontx packages. Peer dependency on axios.

## Core API

- [BaseApiService](https://frontx.dev/docs/api/service): Abstract base class for domain services
- [apiRegistry](https://frontx.dev/docs/api/registry): Central registry for service instances
- [RestProtocol](https://frontx.dev/docs/api/rest): HTTP REST communication
- [MockPlugin](https://frontx.dev/docs/api/mock): Mock data for development/testing

## Key Patterns

- One service per domain (accounts, billing, etc.)
- Services extend BaseApiService
- Mock data registered separately from service
- Plugin system for request/response modification
- Type safety via module augmentation

## Quick Start

```typescript
import { BaseApiService, RestProtocol, apiRegistry, MockMap } from '@gears-frontx/api';

// Define service
class AccountsApiService extends BaseApiService {
  constructor() {
    super({ baseURL: '/api/accounts' }, new RestProtocol());
  }
  async getCurrentUser() {
    return this.protocol(RestProtocol).get('/user/current');
  }
}

// Module augmentation
declare module '@gears-frontx/api' {
  interface ApiServicesMap {
    accounts: AccountsApiService;
  }
}

// Register and use
apiRegistry.register('accounts', AccountsApiService);
apiRegistry.initialize({ useMockApi: true });
const accounts = apiRegistry.getService('accounts');
```

## Optional

- [SSE Protocol](https://frontx.dev/docs/api/sse): Server-Sent Events support
- [Custom Plugins](https://frontx.dev/docs/api/plugins): Auth, logging, retry plugins