docs/site/Rest-Crud-generator.md
{% include content/generator-create-app.html lang=page.lang %}
Adds a new Rest config for model endpoint (or multiple backed by the same datasource) to a LoopBack application with one single command.
lb4 rest-crud [options]
--datasource : (Optional) name of a valid datasource already created in
src/datasources
--model : (Optional) name of a valid model already created in src/models
--basePath : (Optional) base path of the model endpoint
--readonly : (Optional) create readonly APIs e.g find and count
This generator supports a config file with the following format, see the Standard options below to see different ways you can supply this configuration file.
{
"datasource": "validDataSourceName",
"model": "validModelName",
"basePath": "/<base-path>",
"readonly": "<boolean>"
}
Service oriented datasources such as REST or SOAP are not considered valid in this context and will not be presented to you in the selection list.
There should be at least one valid (Persisted) data source and one model already created in their respective directories.
{% include_relative includes/CLI-std-options.md %}
The tool will prompt you for:
Please select the datasource. (name) If the name of the datasource had been supplied from the command line, the prompt is skipped, otherwise it will present you the list of available datasources to select one. It will use this datasource to check what kind of model endpoint it will generate.
Select the model(s) you want to generate a model endpoint. (model) If
the name of the model had been supplied from the command line with --model
option and it is a valid model, then the prompt is skipped, otherwise it will
present the error Error: No models found in the console.
If no --model is supplied, then the it will present you with a valid list of
models from src/models directory and you will be able to select one or
multiple models. The tool will generate a rest config of model endpoint for
each of the selected models.
Please specify the base path.. (basePath) If the base path had been
supplied from the command line with --basePath option or more than one
models are selected, the prompt is skipped.
Create readonly APIs. (readonly) If readonly had been supplied from the
command line with --readonly option, the prompt is skipped.
Once all the prompts have been answered, the CLI will do the following for each of the selected models.
/src/model-endpoints/${modelName}.rest-config.ts