Skip to content

Commit 4baa692

Browse files
committed
Update README.md for improved clarity and formatting in Docker commands and usage instructions
1 parent 3d4385e commit 4baa692

File tree

1 file changed

+76
-19
lines changed

1 file changed

+76
-19
lines changed

README.md

Lines changed: 76 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,45 @@ Check also the [RESTHeart Greetings Services Tutorial](https://restheart.org/doc
2121

2222
🚀 To run and develop this project you can now use the new [RESTHeart command line interface](https://github.com/SoftInstigate/restheart-cli/tree/master). It provides a convenient interface for watching for code changes and automatically rebuilding/redeploying RESTHeart plugins.
2323

24-
After you have installed the cli, follow its [Usage Guide](https://github.com/SoftInstigate/restheart-cli/blob/master/usage-guide.md). It explains how to start from this plugin skeleton to create a __continuous development process__.
24+
After you have installed the cli, follow its [Usage Guide](https://github.com/SoftInstigate/restheart-cli/blob/master/usage-guide.md). It explains how to start from this plugin skeleton to create a **continuous development process**.
2525

2626
### Run with Docker
2727

2828
Follow these steps if you prefer to set up and run the project with docker:
2929

3030
1. Clone the repository:
31+
3132
```bash
32-
$ git clone --depth 1 git@github.com:SoftInstigate/restheart-plugin-skeleton.git
33+
git clone --depth 1 git@github.com:SoftInstigate/restheart-plugin-skeleton.git
3334
```
35+
3436
2. Navigate to the project directory:
37+
3538
```bash
36-
$ cd restheart-plugin-skeleton
39+
cd restheart-plugin-skeleton
3740
```
41+
3842
3. Build and run the container:
43+
3944
```bash
40-
$ ./mvnw clean package && docker run --pull=always --name restheart --rm -p "8080:8080" -v ./target:/opt/restheart/plugins/custom softinstigate/restheart -s
45+
./mvnw clean package && docker run --pull=always --name restheart --rm -p "8080:8080" -v ./target:/opt/restheart/plugins/custom softinstigate/restheart -s
4146
```
4247

4348
> **Note:** 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.
4449
4550
Test the service using:
4651

4752
With curl:
53+
4854
```bash
49-
$ curl localhost:8080/srv
55+
curl localhost:8080/srv
5056
{"message":"Hello World!","rnd":"njXZksfKFW"}%
5157
```
5258

5359
With httpie:
60+
5461
```bash
55-
$ http -b :8080/srv
62+
http -b :8080/srv
5663
{
5764
"message": "Hello World!",
5865
"rnd": "KvQGBwsPBp"
@@ -68,23 +75,29 @@ $ http -b :8080/srv
6875
To run RESTHeart with MongoDB, follow these steps:
6976

7077
1. Launch a MongoDB container:
78+
7179
```bash
72-
$ docker run -d --name mongodb -p 27017:27017 mongo --replSet=rs0
80+
docker run -d --name mongodb -p 27017:27017 mongo --replSet=rs0
7381
```
82+
7483
2. Initialize MongoDB as a Single Node Replica Set:
84+
7585
```bash
76-
$ docker exec mongodb mongosh --quiet --eval "rs.initiate()"
86+
docker exec mongodb mongosh --quiet --eval "rs.initiate()"
7787
```
88+
7889
3. Build and run the RESTHeart container:
90+
7991
```bash
80-
$ ./mvnw clean package && docker run --name restheart --rm -p "8080:8080" -v ./target:/opt/restheart/plugins/custom softinstigate/restheart
92+
./mvnw clean package && docker run --name restheart --rm -p "8080:8080" -v ./target:/opt/restheart/plugins/custom softinstigate/restheart
8193
```
8294

8395
> **Note:** The `-s` option is not used here to enable MongoDB-dependent plugins.
8496
8597
Test a simple GET request:
98+
8699
```bash
87-
$ curl -u admin:secret localhost:8080/users
100+
curl -u admin:secret localhost:8080/users
88101
```
89102

90103
For more details, check the [REST API Tutorial](https://restheart.org/docs/mongodb-rest/tutorial) and the [GraphQL Tutorial](https://restheart.org/docs/mongodb-graphql/tutorial).
@@ -96,17 +109,19 @@ For more details, check the [REST API Tutorial](https://restheart.org/docs/mongo
96109
The default configuration is used. The environment variable `RHO` can be used to override the configuration. See [Change the configuration in Docker container](https://restheart.org/docs/configuration#change-the-configuration-in-docker-container)
97110

98111
Example:
112+
99113
```bash
100-
$ docker run --name restheart --rm -e RHO="/http-listener/host->'0.0.0.0';/mclient/connection-string->'mongodb://host.docker.internal';/helloWorldService/message->'Ciao Mondo!'" -p "8080:8080" -v ./target:/opt/restheart/plugins/custom softinstigate/restheart -s
114+
docker run --name restheart --rm -e RHO="/http-listener/host->'0.0.0.0';/mclient/connection-string->'mongodb://host.docker.internal';/helloWorldService/message->'Ciao Mondo!'" -p "8080:8080" -v ./target:/opt/restheart/plugins/custom softinstigate/restheart -s
101115
```
102116

103117
Here, the `RHO` variable overrides:
118+
104119
- `/http-listener/host`: Sets the host to `0.0.0.0`.
105120
- `/mclient/connection-string`: Specifies the MongoDB connection string.
106121
- `/helloWorldService/message`: Changes the default service message to "Ciao Mondo!".
107122

108123
```bash
109-
$ curl localhost:8080/srv
124+
curl localhost:8080/srv
110125
{"message":"Ciao Mondo!","rnd":"rhyXFHOQUA"}%
111126
```
112127

@@ -119,9 +134,11 @@ Dependencies are managed using Maven. By default, jars are copied to the `target
119134
### Avoid Duplicate JARs
120135

121136
RESTHeart includes several libraries by default. To avoid conflicts:
137+
122138
- Use the `provided` scope for dependencies already included in RESTHeart.
123139

124140
Example:
141+
125142
```xml
126143
<dependency>
127144
<groupId>org.restheart</groupId>
@@ -132,9 +149,10 @@ Example:
132149
```
133150

134151
To list included libraries:
152+
135153
```bash
136-
$ git clone https://github.com/SoftInstigate/restheart.git && cd restheart
137-
$ mvn dependency:tree -Dscope=compile
154+
git clone https://github.com/SoftInstigate/restheart.git && cd restheart
155+
mvn dependency:tree -Dscope=compile
138156
```
139157

140158
---
@@ -144,20 +162,25 @@ $ mvn dependency:tree -Dscope=compile
144162
RESTHeart supports building native images with GraalVM for optimized startup time and memory usage.
145163

146164
### Requirements
165+
147166
- Install GraalVM using [sdkman](https://sdkman.io/):
167+
148168
```bash
149-
$ sdk install java 21.0.3-graal
169+
sdk install java 21.0.3-graal
150170
```
151171

152172
### Build and Run Native Image
153173

154174
1. Build the native image:
175+
155176
```bash
156-
$ ./mvnw clean package -Pnative
177+
./mvnw clean package -Pnative
157178
```
179+
158180
2. Run the binary:
181+
159182
```bash
160-
$ RHO="/fullAuthorizer/enabled->true" target/restheart-plugin-skeleton
183+
RHO="/fullAuthorizer/enabled->true" target/restheart-plugin-skeleton
161184
```
162185

163186
For more details, check [Deploy Java Plugins on RESTHeart native](https://restheart.org/docs/plugins/deploy#deploy-java-plugins-on-restheart-native).
@@ -180,13 +203,47 @@ For more details, check [Deploy Java Plugins on RESTHeart native](https://resthe
180203
### Using Maven Profiles
181204

182205
Activate a profile with the `-P` option:
206+
183207
```bash
184-
$ ./mvnw clean package -Psecurity
208+
./mvnw clean package -Psecurity
185209
```
186210

187211
Combine profiles as needed:
212+
188213
```bash
189-
$ ./mvnw clean package -Psecurity,mongodb
214+
./mvnw clean package -Psecurity,mongodb
190215
```
191216

192217
For more details, refer to the `pom.xml` file.
218+
219+
### Profile Matrix (Common Scenarios)
220+
221+
Use this matrix to pick the right profiles and commands for typical setups.
222+
223+
| Scenario | Profiles | Build Command | Run Command |
224+
| --- | --- | --- | --- |
225+
| Standalone demo (no MongoDB) | _(none)_ or `security`/`metrics` as needed | \`./mvnw clean package\` | \`docker run --pull=always --name restheart --rm -p "8080:8080" -v ./target:/opt/restheart/plugins/custom softinstigate/restheart -s\` |
226+
| MongoDB development (insecure dev only) | `mongodb` | \`./mvnw clean package -Pmongodb\` | \`docker run -d --name mongodb -p 27017:27017 mongo --replSet=rs0\` then \`docker exec mongodb mongosh --quiet --eval "rs.initiate()"\` then \`docker run --name restheart --rm -p "8080:8080" -v ./target:/opt/restheart/plugins/custom softinstigate/restheart\` |
227+
| Secured MongoDB API | `security,mongodb` | \`./mvnw clean package -Psecurity,mongodb\` | Same as MongoDB development (without `-s`) |
228+
| GraphQL over MongoDB | `graphql,mongodb` (add `security` if needed) | \`./mvnw clean package -Pgraphql,mongodb\` | Same as MongoDB development (without `-s`) |
229+
| Metrics enabled | `metrics` (+ combine with others) | \`./mvnw clean package -Pmetrics\` | Combine with your chosen run mode |
230+
| Native executable (bundles RESTHeart + plugin) | `native` (+ combine modules at build time is not supported; native already bundles required RESTHeart artifacts) | \`sdk install java 21.0.3-graal\` then \`./mvnw clean package -Pnative\` | \`RHO="/fullAuthorizer/enabled->true" target/restheart-plugin-skeleton\` |
231+
232+
Notes:
233+
234+
- Docker `-s` flag runs in standalone mode (disables MongoDB-dependent plugins). Do not use `-s` when you enable `mongodb` profile.
235+
- In default (non-`native`) builds, RESTHeart core dependencies are treated as `provided`; your plugin JAR plus `target/lib` contains only external runtime deps.
236+
- Avoid heavy static initializers in plugins to keep GraalVM native-image builds smooth.
237+
238+
---
239+
240+
## Debugging & Logs
241+
242+
- RESTHeart logs to stdout/stderr in Docker and to console in native runs. Inspect container logs for plugin issues:
243+
244+
```bash
245+
docker logs -f restheart
246+
```
247+
248+
- If your service returns `405`, verify the HTTP method handling in `src/main/java/org/restheart/examples/HelloWorldService.java` and ensure `OPTIONS` is handled via `handleOptions(req)` for CORS.
249+
- To adjust service behavior at runtime, prefer `RHO` env overrides instead of code changes (e.g., `/helloWorldService/message`).

0 commit comments

Comments
 (0)