0.0.1-alpha.0 • Published 7 months ago

@lcimb/ts-jsonforms-server v0.0.1-alpha.0

Weekly downloads
-
License
-
Repository
-
Last release
7 months ago

Express Tools for TypeScript To JsonForms

This is a proof of concept for using TypeScript interfaces to generate forms using ts-json-schema-generator and jsonforms.

The above mentioned packages are great, and I am convinced that tying them together will create something awesome.

This is experimental and subject to change.

Example Usage

import express, { Router } from "express";
import ViteExpress from "vite-express";
import bodyParser from "body-parser";
import { SchemaHandler } from "ts-to-json-forms-server/dist/schema-handler.js";
import Test1 from "../../schemas/test1.js";
import Test2 from "../../schemas/test2.js"

const app = express();

const schemaHandler = new SchemaHandler({
  schemaDir: "./schemas",
});

app.use(bodyParser.json());

const api = Router()  
app.use("/api", api)

api
  .route("/test1")
  .post<any, any, Test1>(schemaHandler.validate(), (req, res) => {
    res.send(req.body);
  })
  .get(schemaHandler.serveSchema());

api
  .route("/test2")
  .post<any, any, Test2>(schemaHandler.validate(), (req, res) => {
    res.send(req.body);
  })
  .get(schemaHandler.serveSchema());

api
  .route("/test3")
  .post(schemaHandler.validate(), (req, res) => {
    res.send(req.body);
  })
  .get(schemaHandler.serveSchema());

ViteExpress.listen(app, 3000, () => {
  console.log("http://localhost:3000");
});
0.0.1-alpha.0

7 months ago