This guide provides practical examples for common workflows with the RESTHeart CLI.
- Quickstart
- Installation
- Development Workflow
- Build and Deployment
- Process Management
- Advanced Usage
- Troubleshooting
RESTHeart CLI makes it easy to develop and test plugins for RESTHeart. Here's how to get started:
To create a new RESTHeart plugin project:
-
Clone the plugin skeleton repository:
git clone https://github.com/SoftInstigate/restheart-plugin-skeleton my-plugin cd my-plugin -
Customize the project (optional):
- Open the
pom.xmlfile - Update the
groupIdfromorg.restheartto your organization - Update the
artifactIdfromrestheart-plugin-skeletonto your project name
- Open the
The -s option (standalone mode) disables MongoDB-dependent plugins. Use this option if you do not intend to connect to a MongoDB instance during runtime.
-s option RESTHeart tries to connect to a MongoDB instace running at localhost:27017. If that is not present then RESTHeart fails to start.
Once you have your plugin project set up:
# Install RESTHeart (if you haven't already)
rh install
# Build your plugin
rh build
# Run RESTHeart with your plugin (passing the -s standalone flag, to avoid connecting to MongoDB)
rh run -- -s
# For active development, use watch mode (passing the -s standalone flag, to avoid connecting to MongoDB)
# the optional --build flag forces an initial rebuild of the project
rh watch --build -- -sThe watch mode will automatically rebuild and restart RESTHeart whenever you make changes to your code, making the development process much smoother.
💡 You can use the rh command with the run or watch option passing the /mclient/connection-string via the RHO environmemt variable, to connect to a specific MongoDB instance. This way, you can develop locally but using a remote database.
Example:
RHO='/mclient/connection-string->"mongodb://192.168.1.100:27017"' rh watchAfter setting up your plugin project, you can:
- Explore the sample code in the
srcdirectory - Modify the plugin code to implement your desired functionality
- Refer to the RESTHeart documentation for detailed information on plugin development
Install the latest version of RESTHeart:
rh installThis will:
- Download the latest RESTHeart release
- Extract it to the
.cache/restheartdirectory - Set up the required directory structure
rh install 8.10.1Force a clean reinstallation:
rh install --forceStart a development environment with auto-rebuild:
# Start with file watching (auto-rebuild on changes)
rh watch
# Start with file watching using a custom config file
rh watch -- -o etc/dev-config.yml💡 Have a look at the configuration section in the official documentation for the available configuration options.
Watch with custom settings:
# Watch on a different port
rh watch --port 9090
# Watch with initial build
rh watch --build
# Watch with longer debounce time (wait longer between changes)
rh watch --debounce-time 2000
# Watch with debug information
rh watch --debugEnable verbose output for detailed logs:
rh watch --verboseView the RESTHeart log file:
tail -f restheart.logConnect to the JDWP debug port (default: HTTP port + 1000):
# If HTTP port is 8080, debug port is 9080
# Configure your IDE to connect to localhost:9080Build and deploy plugins in the current directory:
rh buildRun RESTHeart with an automatic build before starting:
# Build and run in a single command
rh run --build💡 Have a look at the configuration section in the official documentation for the available configuration options.
# Run with a custom configuration file
rh run -- -o etc/custom-config.yml
# Build, then run with a custom configuration file
rh run --build -- -o etc/custom-config.ymlrh status# Start RESTHeart
rh run
# Stop RESTHeart
rh kill
# Start on a different port
rh run --port 9090
# Stop instance on a specific port
rh kill --port 9090Run multiple instances on different ports:
# Start first instance
rh run --port 8080
# Start second instance (in a new terminal)
rh run --port 9090# Build and run in debug mode
rh run --build --debug
# Build and run with verbose logging
rh run --build --verboseConfigure logging verbosity:
# Only show errors
rh --quiet run
# Show verbose debug information
rh --verbose run
# Add timestamps to logs
rh --timestamps run--debug: Enables debug mode in the RESTHeart application itself, showing internal configuration details.--verbose: Increases the CLI tool's log level to show more detailed information.
# For complete diagnostic information, use both:
rh run --debug --verboseFor CI/CD environments, the progress spinners will be automatically disabled. Additional flags for CI environments:
# Run silently (minimal output)
rh --quiet build
# Run with timestamps for better log tracing
rh --timestamps buildError: Port 8080 is already in use
Resolution:
# Kill any instances using that port
rh kill --port 8080
# Or start on a different port
rh run --port 9090Error: Maven build failed
Resolution:
# Check the Maven build directly
./mvnw clean package
# Try with verbose output
rh --verbose buildError: RESTHeart failed to start
Resolution:
# Check the log file
cat restheart.log
# Try with debug mode
rh --debug run