Create a new API instance
Define an API
import { schema, type Schema } from "./schema"; import { createApi, handler as $ } from "../src/api"; const api = createApi( schema, ({client}) => ({ // *note* The keys of the record must not start with a slash 'example-users': { get: $<Schema['users'][]>(async (req, res) => { const users = await client.query('SELECT * FROM users WHERE email ilike $1', [`%example.com%`]); res.status(200).json(users.rows); }), post: $<Schema['users'], Schema['users']>(async (req, res) => { const user = await client.query('select * from users where id = 2'); res.status(200).json(user.rows[0]); }) } }), { caseConversion: { in: 'snake', out: 'camel', }, pagination: { defaultPage: 1, defaultLimit: 10, } } ); export default api; * ``` Copy
import { schema, type Schema } from "./schema"; import { createApi, handler as $ } from "../src/api"; const api = createApi( schema, ({client}) => ({ // *note* The keys of the record must not start with a slash 'example-users': { get: $<Schema['users'][]>(async (req, res) => { const users = await client.query('SELECT * FROM users WHERE email ilike $1', [`%example.com%`]); res.status(200).json(users.rows); }), post: $<Schema['users'], Schema['users']>(async (req, res) => { const user = await client.query('select * from users where id = 2'); res.status(200).json(user.rows[0]); }) } }), { caseConversion: { in: 'snake', out: 'camel', }, pagination: { defaultPage: 1, defaultLimit: 10, } } ); export default api; * ```
import api from './api';api.start().then((err) => { if (err) { console.error(err); } else { console.log(`API is running on port ${api.config.port}`); }}); Copy
import api from './api';api.start().then((err) => { if (err) { console.error(err); } else { console.log(`API is running on port ${api.config.port}`); }});
Copy
Description
Create a new API instance
Example
Define an API
Example