DEV Community

Alex Spinov
Alex Spinov

Posted on

Directus Has a Free API You've Never Heard Of

Directus is an open-source data platform that wraps any SQL database with a REST and GraphQL API, plus an admin app. Point it at your existing database and get a full API instantly — no migration needed.

What Makes Directus Special?

  • Database-first — wraps ANY existing SQL database
  • No migration — point at existing tables, get instant API
  • REST + GraphQL — both APIs auto-generated
  • Admin app — beautiful, customizable admin panel
  • Free self-hosted — unlimited everything

The Hidden API: Instant API from Database

# Connect to existing database — instant API
docker run -e DB_CLIENT=postgres \
  -e DB_HOST=localhost \
  -e DB_DATABASE=myapp \
  -p 8055:8055 directus/directus

# Every table becomes an API endpoint
GET  /items/products?filter[price][_gte]=10&sort=-created_at&limit=20
POST /items/products
PATCH /items/products/123
DELETE /items/products/123
Enter fullscreen mode Exit fullscreen mode

SDK API — Type-Safe Client

import { createDirectus, rest, readItems, createItem } from '@directus/sdk';

const client = createDirectus<Schema>('http://localhost:8055').with(rest());

// Read with filtering
const products = await client.request(
  readItems('products', {
    filter: { price: { _gte: 10 } },
    sort: ['-created_at'],
    limit: 20,
    fields: ['id', 'title', 'price', { category: ['name'] }]
  })
);

// Create
const newProduct = await client.request(
  createItem('products', {
    title: 'New Widget',
    price: 29.99,
    category: 'electronics'
  })
);
Enter fullscreen mode Exit fullscreen mode

Flows API — Visual Automation

{
  "trigger": { "type": "event", "event": "items.create", "collection": "orders" },
  "operations": [
    { "type": "mail", "to": "{{$trigger.payload.email}}", "subject": "Order Confirmed" },
    { "type": "request", "url": "https://api.stripe.com/v1/charges", "method": "POST" },
    { "type": "item-update", "collection": "orders", "payload": { "status": "processing" } }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Real-Time API — WebSocket

import { createDirectus, realtime } from '@directus/sdk';

const client = createDirectus<Schema>('ws://localhost:8055').with(realtime());

client.onWebSocket('message', (data) => {
  if (data.type === 'subscription') {
    console.log('Update:', data.data);
  }
});

await client.subscribe('products', { event: 'create' });
Enter fullscreen mode Exit fullscreen mode

Quick Start

npx create-directus-project my-project
cd my-project && npx directus start
Enter fullscreen mode Exit fullscreen mode

Why Teams Choose Directus

A developer shared: "We had a legacy PostgreSQL database with 50 tables. Directus gave us a REST API, GraphQL, and admin panel for all 50 tables in 10 minutes. No code, no migration, no ORM mapping."


Need data tools or automation? Email spinov001@gmail.com or check my solutions.

How do you expose database APIs? Directus vs Hasura vs PostgREST?

Top comments (0)