Hi, developers!

Read this spec first

name: My API app
port: 8080
path: /api
database: mysql
models:
  - users:
    - table users:
        get:
          - int id
          - varchar name
          - varchar email
press [space] to continue

Can you write a database API app in a few minutes?

Let's get started!

press [space] to continue

You will code SQL for database.

module.exports.mydb = {
  "get users": async () => {
    const result = await sql.query`SELECT
      id,
      name,
      email
    FROM users `;

    return result.recordset;
  },
}
press [space] to continue

You will also code the API route.

const model = require('./model');
const express = require('express');
const app = express();

app.get('/api/users', async (req, res) => {
  const result = await model.mydb['users:get']();
  res.json(result);
});

const port = process.env.port || 8080;
app.listen(port, () => {
  console.log(`API server listening on port ${port}`);
});
press [space] to continue

Then, if there are many of such to code

models:
  - users:
    - table users:
        get:
        get /users/:id:
        post:
        put /users/:id:
        patch /users/:id/name:
        patch /users/:id/email:
        delete /users/:id:
    - procedure: usp_update_user
press [space] to continue

It certainly takes time to write all of them. What if you can

Generate the Code

npx create-data-api-app

And run code in a few seconds.

node server.js
press [space] to continue

Plus, you also get the OpenApi spec.

openapi: '3.0.0'
info:
  title: My API app
  version: "1.0"
servers:
  - url: https://localhost:8080
paths:
  /api/users:
    get:
      summary: users:get
      responses:
        '200':
          description: OK
press [space] to continue

And, some code for testing.

@host=http://localhost:8080

###
GET {{host}}/api/users

###
GET {{host}}/api/users/:id

###
POST {{host}}/api/users
Content-Type: application/json
{
  "name": "",
  "email": ""
}
press [space] to continue

Try it yourself!

npx create-data-api-app

the end