docs/site/Service-generator.md
{% include content/generator-create-app.html lang=page.lang %}
Adds a new Service class to a LoopBack application with one single command.
lb4 service [options] [<name>]
--type : (Optional) service type: proxy, class, or provider
--datasource : (Optional) name of a valid REST or SOAP datasource already
created in src/datasources
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.
{
"name": "serviceNameToBeGenerated",
"datasource": "validDataSourceName",
}
We support three types of services now:
Provider interface and can be
bound to the application contextFor remote services (type=proxy), there should be at least one valid (REST or
SOAP) data source created already in the src/datasources directory.
{% include_relative includes/CLI-std-options.md %}
<name> - Optional argument specifying the service name to be generated.
The tool will prompt you for:
Service type. (serviceType) If the service type had been supplied from
the command line with --type or --datasource (implying proxy) option and
it is a valid one, then the prompt is skipped, otherwise it will present you
the list of all valid service types.
? Service type: (Use arrow keys)
❯ Remote service proxy backed by a data source
Local service class bound to application context
Local service provider bound to application context
Please select the datasource. (datasource) If the name of the datasource
had been supplied from the command line with --datasource option and it is a
valid one, then the prompt is skipped, otherwise it will present you the list
of all valid datasources from the src/datasources directory.
Service name. (name) If the name of the service to be generated had been supplied from the command line, the prompt is skipped.
Once all the prompts have been answered, the CLI will generate a basic skeleton for your service.
/src/services/${name}.service.ts/src/services/index.ts to export the newly created Service class.