Docs/API Reference

ClientAPI Reference

Backend-as-a-service layer with secure, scalable API for all data operations.

ClientAPI Reference

Overview

The ClientAPI is the backend-as-a-service layer that powers your applications. It provides a secure, scalable API for all data operations with built-in security, caching, and extensibility.


Architecture

┌─────────────────────────────────────────────────────────────────┐
│                         ClientAPI                                │
├─────────────────────────────────────────────────────────────────┤
│  ┌─────────────────────────────────────────────────────────┐    │
│  │                    CORE (Platform)                       │    │
│  │  • Authentication & Authorization                        │    │
│  │  • Universal Row-Level Security (RLS)                    │    │
│  │  • Entity Operations (CRUD)                              │    │
│  │  • Permission Service                                    │    │
│  │  • Caching Layer                                         │    │
│  │  • Database Management                                   │    │
│  └─────────────────────────────────────────────────────────┘    │
│                              │                                   │
│                              ▼                                   │
│  ┌─────────────────────────────────────────────────────────┐    │
│  │                   CUSTOM (Client-Authored)               │    │
│  │  • Server Functions (TypeScript/JavaScript)              │    │
│  │  • Business Logic                                        │    │
│  │  • Third-party Integrations                              │    │
│  │  • Custom Validation                                     │    │
│  └─────────────────────────────────────────────────────────┘    │
└─────────────────────────────────────────────────────────────────┘

Core vs Custom

AspectCoreCustom
OwnershipPlatformClient
Code VisibilityObfuscatedFull access
UpdatesAutomaticClient-managed
PurposeInfrastructureBusiness logic
ExamplesRLS, CRUD, authOrder processing, reports

Authentication

API Key Authentication

http
GET /api/entities/products
Authorization: Bearer YOUR_API_KEY
X-Workspace-Id: workspace-uuid

JWT Authentication (User Context)

http
POST /api/auth/login
Content-Type: application/json

{
  "email": "user@example.com",
  "password": "secure-password"
}

Response:

json
{
  "access_token": "eyJhbGciOiJIUzI1NiIs...",
  "refresh_token": "eyJhbGciOiJIUzI1NiIs...",
  "expires_in": 3600,
  "user": {
    "id": "user-uuid",
    "email": "user@example.com",
    "roles": ["admin"]
  }
}

Entity Operations

Create (POST)

http
POST /api/entities/products
Content-Type: application/json

{
  "name": "Premium Widget",
  "description": "High-quality widget for professionals",
  "price": 99.99,
  "category_id": "category-uuid",
  "is_active": true
}

Read (GET)

Find by ID

http
GET /api/entities/products/product-uuid

List with Filtering

http
GET /api/entities/products?
  filter[is_active]=true&
  filter[price][gte]=50&
  filter[category_id]=category-uuid&
  sort=-created_at&
  limit=10&
  offset=0&
  expand=category

Query Parameters

ParameterDescriptionExample
filter[field]Exact matchfilter[status]=active
filter[field][op]Operatorfilter[price][gte]=100
sortOrder resultssort=-created_at,name
limitMax resultslimit=25
offsetSkip recordsoffset=50
expandInclude relationsexpand=category,tags
fieldsSelect fieldsfields=id,name,price

Filter Operators

OperatorDescriptionExample
eqEqual (default)filter[status][eq]=active
neNot equalfilter[status][ne]=deleted
gtGreater thanfilter[price][gt]=100
gteGreater or equalfilter[price][gte]=100
ltLess thanfilter[quantity][lt]=10
lteLess or equalfilter[quantity][lte]=10
inIn arrayfilter[status][in]=active,pending
ninNot in arrayfilter[status][nin]=deleted,archived
likePattern matchfilter[name][like]=%widget%
nullIs nullfilter[deleted_at][null]=true

Update (PUT/PATCH)

http
PATCH /api/entities/products/product-uuid
Content-Type: application/json

{
  "price": 89.99,
  "is_active": false
}

Delete (DELETE)

http
DELETE /api/entities/products/product-uuid

Bulk Operations

Bulk Create

http
POST /api/entities/products/bulk
Content-Type: application/json

{
  "records": [
    { "name": "Product 1", "price": 29.99 },
    { "name": "Product 2", "price": 39.99 },
    { "name": "Product 3", "price": 49.99 }
  ]
}

Error Handling

Error Response Format

json
{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Validation failed",
    "details": [
      {
        "field": "email",
        "message": "Invalid email format"
      }
    ]
  }
}

Error Codes

CodeHTTP StatusDescription
UNAUTHORIZED401Invalid or missing authentication
FORBIDDEN403Permission denied
NOT_FOUND404Resource not found
VALIDATION_ERROR400Invalid input data
CONFLICT409Resource already exists
RATE_LIMITED429Too many requests
INTERNAL_ERROR500Server error

Rate Limiting

TierRequests/minRequests/day
Free6010,000
Pro600100,000
Enterprise6,000Unlimited

Rate limit headers:

http
X-RateLimit-Limit: 600
X-RateLimit-Remaining: 542
X-RateLimit-Reset: 1705312800

SDK Usage

JavaScript/TypeScript

typescript
import { AlgorithmShiftClient } from '@algorithmshift/client';

const client = new AlgorithmShiftClient({
  workspaceId: 'workspace-uuid',
  apiKey: 'your-api-key'
});

// Entity operations
const products = await client.entities.products.find({
  where: { is_active: true },
  orderBy: { created_at: 'desc' },
  limit: 10,
  expand: ['category']
});

// Create record
const newProduct = await client.entities.products.create({
  name: 'New Product',
  price: 29.99
});

// Call custom function
const result = await client.functions.call('orders/process-order', {
  orderId: 'order-uuid',
  paymentToken: 'tok_visa'
});

React Hooks

typescript
import { useEntities, useFunction } from '@algorithmshift/react';

function ProductList() {
  const { data, loading, error, refetch } = useEntities('products', {
    where: { is_active: true },
    orderBy: { name: 'asc' }
  });

  const [processOrder, { loading: processing }] = useFunction(
    'orders/process-order'
  );

  if (loading) return <Spinner />;
  if (error) return <Error message={error.message} />;

  return (
    <ProductGrid products={data} />
  );
}