Files
restloom/docs/getting-started.md
T

1.2 KiB

Getting started

Install

Install the core, the package for your database, and its driver:

npm install @crudy/restloom @crudy/restloom-postgres pg
Database Package Driver
PostgreSQL 13+ @crudy/restloom-postgres pg

Serve a schema

import http from 'node:http';
import pg from 'pg';
import { createREST, nodeListener } from '@crudy/restloom';
import { postgres } from '@crudy/restloom-postgres';

const rest = createREST({
    db: postgres(new pg.Pool({ connectionString: process.env.DATABASE_URL })),
    expose: { schemas: ['app'] },
});

http.createServer(nodeListener(rest, { prefix: '/api' })).listen(3000);

Every table and view of app is now a resource, read-only:

curl -g 'http://localhost:3000/api/assets?select=id,name,owner(name)&status=eq.open'

Next