Create REST endpoint plugin

A plugin to create a REST endpoint configuration file in a light module.

Package name

@magnolia/cli-create-rest-endpoint-plugin

Repository link

Latest version

Magnolia CLI create rest endpoint plugin - latest version tag

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 (--) in quotes:

npm run mgnl "--" ...

The command automatically downloads, installs, and registers the plugin in the mgnl.config.js file.

Manually

  1. Run the following command in the project folder.

    npm install @magnolia/cli-create-rest-endpoint-plugin
  2. Modify the mgnl.config.js file accordingly.

    import CreateRestEndpointPlugin from "@magnolia/cli-create-rest-endpoint-plugin";
    
    export default {
      plugins: [
        new CreateRestEndpointPlugin()
      ]
    };

Usage

Command

create-rest-endpoint <name> [options]

Options

Form (short and long) Description

-d [path]

--destination [path]

Sets the destination (subdirectory) of the REST endpoint file. By default, /delivery or the value specified in the mgnl.config.js file is used.

-w [name]

--workspace [name]

Sets the workspace name for the endpoint. Uses website by default.

-lm [name]

--light-module [name]

Sets a light module for the REST endpoint. By default, uses the directory specified in the mgnl.config.js file.

-v

--version

Displays the version.

-h

--help

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 "my-rest-endpoint"

Windows users using PowerShell must enclose the two consecutive hyphens (--) in quotes:

npm run mgnl "--" ...

The command creates a REST endpoint called my-rest-endpoint with the website workspace in the ./restEndpoints/delivery folder.

It also checks the light module folder for component templates 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 a custom workspace name

npm run mgnl -- create-rest-endpoint "my-rest-endpoint" --workspace "foo"

Windows users using PowerShell must enclose the two consecutive hyphens (--) in quotes:

npm run mgnl "--" ...

The command creates a REST endpoint called my-rest-endpoint with the foo workspace in the ./restEndpoints/delivery folder.

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 "my-rest-endpoint" --workspace "foo" --destination "/zig"

Windows users using PowerShell must enclose the two consecutive hyphens (--) in quotes:

npm run mgnl "--" ...

The command creates a REST endpoint called my-rest-endpoint with the foo workspace in the ./restEndpoints/zig folder.

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 "my-rest-endpoint" --light-module "my-lm"

Windows users using PowerShell must enclose the two consecutive hyphens (--) in quotes:

npm run mgnl "--" ...

The command creates a REST endpoint called my-rest-endpoint with the website workspace in the ./restEndpoints/delivery folder.

It also checks the light module folder for component templates 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

lightModulesPath

The path to a directory containing all light modules.

lightModule

The name of a light module where the endpoints will be created.

Alternative forms: -lm [name], --light-module [name]

Plugin properties

Property name Description

lightModule

The name of a light module where the endpoints will be created.

Alternative forms: -lm [name], --light-module [name]

destination

The path to a custom restEndpoints subdirectory where the endpoints will be created.

Alternative forms: -d [path], --destination [path]

For more information, see Configuring plugins.

Feedback

DX Core

×

Location

This widget lets you know where you are on the docs site.

You are currently perusing through the Magnolia CLI docs.

Main doc sections

DX Core Headless PaaS Legacy Cloud Incubator modules