ethanresnick / json-api

Turn your node app into a JSON API server (http://jsonapi.org/)
GNU Lesser General Public License v3.0
268 stars 41 forks source link

dynamicly update(add remove update) the model definition and registry definition #108

Closed futurist closed 8 years ago

futurist commented 8 years ago

How to dynamicly update(add remove update) the model definition and registry definition?

Like the below demo code

  var adapter = new API.dbAdapters.Mongoose(modelDefinition);
  var registry = new API.ResourceTypeRegistry(registryDefinition);
  //need to add new registry type later...
ethanresnick commented 8 years ago

This used to be possible, but I removed the feature recently, because requiring all definitions be provided to the registry upfront ends up dramatically simplified some of the internal logic and reduced the possibility for bugs. See this commit message for more context.

So, I'd suggest just adding definitions to the registryDefinition object (from your samle code) over time, but don't pass that object to the registry until it's all ready.

futurist commented 8 years ago

after update registryDefinition when service already started, how to restart the service in code with minimum reset? that to say,

  // Initialize the automatic documentation.
  var DocsController = new API.controllers.Documentation(registry, {name: 'Example API'});

  // Set up our controllers
  var APIController = new API.controllers.API(registry);
  var Front = new API.httpStrategies.Express(APIController, DocsController);
  var requestHandler = Front.apiRequest.bind(Front);

if want to use new registryDefinition, need re-construct all 4 variables? seems heavy; any light way to restart the service?

ethanresnick commented 8 years ago

Out of curiosity, why do you need to update the registry after the service has already started? (When I changed the registry code earlier to require all definitions upfront, I assumed that updating it after the service started wouldn't be necessary. But, if there's a good reason for this, I'm happy to reconsider my earlier change.)

futurist commented 8 years ago

The project now is similar to typeform

It's dynamically create forms by users, and user can submit data using newly created forms.

Besides, I think there's some need for the situation, which user need to interact with the data structure.