Create REST endpoint plugin
A plugin to create a REST endpoint configuration files in a light module.
| Package name | 
 | 
| Repository link | |
| Latest version | |
| Changelog link | 
Installing
The plugin doesn’t come pre-installed with Magnolia CLI.
You must add it to the mgnl.config.js project file.
| The plugin is installed automatically by the Jumpstart plugin if it is defined in a project template. | 
With add-plugin
Run the following command in the project folder.
npm run mgnl -- add-plugin @magnolia/cli-create-rest-endpoint-plugin| Windows users using PowerShell must enclose the two consecutive hyphens (  | 
The command automatically downloads, installs, and registers the plugin in the mgnl.config.js file.
Manually
- 
Run the following command in the project folder. npm install @magnolia/cli-create-rest-endpoint-plugin
- 
Modify the mgnl.config.jsfile accordingly.import CreateRestEndpointPlugin from "@magnolia/cli-create-rest-endpoint-plugin"; export default { plugins: [ new CreateRestEndpointPlugin() ] };
Usage
Command
create-rest-endpoint [workspace] [options]By default (without the workspace argument), REST endpoints are created for all workspaces found in the light module directory including the website workspace.
To create an endpoint for a specific workspace only, provide the workspace name as an argument.
Options
| Form (short and long) | Description | 
|---|---|
| 
 
 | Sets the destination (subdirectory) of the REST endpoint file.
By default,  | 
| 
 
 | Sets a light module for the REST endpoint.
By default, uses the directory specified in the  | 
| 
 
 | Pass file path(s) to detect workspaces and generate endpoints accordingly. | 
| 
 
 | Displays the version. | 
| 
 
 | Displays help information. | 
Examples
For the following examples, it’s assumed that the mgnl.config.js file looks like this:
import CreateRestEndpointPlugin from "@magnolia/cli-create-rest-endpoint-plugin";
export default {
  plugins: [
    new CreateRestEndpointPlugin()
  ]
};For more information, see Configuring plugins.
Endpoint with default values
npm run mgnl -- create-rest-endpoint| Windows users using PowerShell must enclose the two consecutive hyphens (  | 
The command creates REST endpoints for all workspaces found in the light module directory including the website workspace.
For the website workspace, it creates an endpoint named pages_v1, and for other workspaces it creates endpoints named [workspace]_v1.
If any endpoint file already exists, the plugin automatically increments the version numbers (for example, pages_v2, foo_v3, etc.).
All endpoints are created in the ./restEndpoints/delivery folder.
It also checks the light module folder for content types and apps (and component templates for the website workspace) with such a workspace and creates reference resolvers for the properties it finds.
The plugin will prompt you to:
- 
Choose a directory containing all light modules. 
- 
Choose a light module directory where the endpoint configuration file will be created. 
The plugin writes the following properties to the mgnl.config.js file:
- 
Global - 
lightModulesPath
 
- 
- 
Plugin - 
lightModule
 
- 
Endpoint for a specific workspace
npm run mgnl -- create-rest-endpoint "foo"| Windows users using PowerShell must enclose the two consecutive hyphens (  | 
The command creates a REST endpoint only for the workspace specified ("foo").
The endpoint will be named foo_v1 in the ./restEndpoints/delivery folder.
If foo_v1.yaml already exists, the plugin will automatically increment the version number (to foo_v2.yaml, foo_v3.yaml, and so on).
It also checks the light module folder for content types and apps with such a workspace and creates reference resolvers for the properties it finds.
The plugin will prompt you to:
- 
Choose a directory containing all light modules. 
- 
Choose a light module directory where the endpoint configuration file will be created. 
The plugin writes the following properties to the mgnl.config.js file:
- 
Global - 
lightModulesPath
 
- 
- 
Plugin - 
lightModule
 
- 
Endpoint with custom workspace and destination values
npm run mgnl -- create-rest-endpoint "foo" --destination "/zig"| Windows users using PowerShell must enclose the two consecutive hyphens (  | 
The command creates a REST endpoint only for the workspace specified ("foo").
The endpoint will be named foo_v1 in the ./restEndpoints/zig folder.
If foo_v1.yaml already exists, the plugin will automatically increment the version number (to foo_v2.yaml, foo_v3.yaml, and so on).
It also checks the light module folder for content types and apps with such a workspace and creates reference resolvers for the properties it finds.
The plugin will prompt you to:
- 
Choose a directory containing all light modules. 
- 
Choose a light module directory where the endpoint mapping will be created. 
The plugin writes the following properties to the mgnl.config.js file:
- 
Global - 
lightModulesPath
 
- 
- 
Plugin - 
lightModule
 
- 
Endpoint in a specific light module
npm run mgnl -- create-rest-endpoint --light-module "my-lm"| Windows users using PowerShell must enclose the two consecutive hyphens (  | 
The command creates REST endpoints for all workspaces found in the "my-lm" light module.
For the website workspace, it creates an endpoint named pages_v1, and for other workspaces it creates endpoints named [workspace]_v1.
If any endpoint file already exists, the plugin automatically increments the version numbers (for example to pages_v2, foo_v3, and so on).
All endpoints are created in the ./restEndpoints/delivery folder.
It also checks the light module folder for content types and apps (and component templates for the website workspace) with such a workspace and creates reference resolvers for the properties it finds.
The plugin prompts you to choose a directory containing all light modules.
If the my-lm light module doesn’t exist yet in the light modules directory, the plugin will prompt you to select another one.
The plugin writes the following properties to the mgnl.config.js file:
- 
Global - 
lightModulesPath
 
- 
- 
Plugin - 
lightModule
 
- 
Configuration
In mgnl.config.js, you can set the following properties to predefine the plugin’s behavior.
Global properties
| Property name | Description | 
|---|---|
| 
 | The path to a directory containing all light modules. | 
| 
 | The name of a light module where the endpoints will be created. Alternative forms:  | 
Plugin properties
| Property name | Description | 
|---|---|
| 
 | The name of a light module where the endpoints will be created. Alternative forms:  | 
| 
 | The path to a custom  Alternative forms:  | 
For more information, see Configuring plugins.