Sunday 21 May 2017

Right way to construct forms with a RestAPI server

Here is a question:

How am I suppose to construct forms in front end when there is a RestAPI server?

Here is a situation:

There is a Node.js RestAPI server that uses mongoose to communicate with a db. So, there are some mongoose models and the server want to get json from outside in a correct format.

Here is ways how to do it:

  1. Just construct a form in front end by the hands that satisfies the correct format
  2. Hold JSON-Schema on server and ask it from front end

Here is problems in the solutions:

  1. It seems a bit inconvenient to repair the form after model changing
  2. Mongoose-Schemas and JSON-Schemas have different structure, so I have to have two copies of schema just in different formats. Therefore, there is the problem from point 1

Here is possible solutions of the problems:

  1. ?
  2. Maybe there are some utils to use JSON-Schema to create Mongoose-Schema or utils to create JSON-Schema from Mongoose-Schema? But I cannot really imagine, how should the 'json-schema -> mongoose-schema' work.

So, here is the questions again:

  • What is the right way to create forms with a RestAPI server?
  • Are there some good utils that let me construct json-schema from mongoose-schema?
  • How is it accepted to do?


via Slava Vikharev

No comments:

Post a Comment