|
1 | | -🚀 Helidon WebServer – Basic Example |
| 1 | +##WebServer Basic Example |
2 | 2 |
|
3 | | -This example demonstrates the simplest possible Helidon SE WebServer application. |
4 | | -It shows how to start a server, define basic routing, handle HTTP requests, and return responses. |
| 3 | +This example demonstrates a minimal Helidon WebServer application that starts an HTTP server and exposes simple routes. |
5 | 4 |
|
6 | | -This is a good starting point for understanding how Helidon SE applications are structured. |
| 5 | +##Project Structure |
7 | 6 |
|
8 | | -📂 Project Structure |
9 | | -basic/ |
| 7 | +``` |
| 8 | +webserver-basic/ |
| 9 | + ├── src |
| 10 | + │ └── main |
| 11 | + │ └── java |
| 12 | + │ └── io/helidon/examples/webserver/basic/ |
| 13 | + │ ├── Main.java |
| 14 | + │ └── GreetService.java |
10 | 15 | ├── pom.xml |
11 | | - └── src |
12 | | - ├── main |
13 | | - │ ├── java/io/helidon/examples/webserver/basic/BasicMain.java |
14 | | - │ └── resources/logging.properties |
15 | | - └── test |
16 | | - └── java/io/helidon/examples/webserver/basic/ |
17 | | - ├── AbstractBasicRoutingTest.java |
18 | | - ├── BasicRoutingIT.java |
19 | | - └── BasicRoutingTest.java |
| 16 | + └── README.md |
20 | 17 |
|
21 | | -🧠 What This Example Shows |
22 | | -✔ Start a WebServer |
| 18 | +``` |
| 19 | +##Build |
23 | 20 |
|
24 | | -The example configures and starts a Helidon SE WebServer on a selected port. |
| 21 | +Use Maven to compile the project: |
25 | 22 |
|
26 | | -✔ Define Basic Routing |
| 23 | +mvn clean install |
27 | 24 |
|
28 | | -It demonstrates simple routing, including: |
| 25 | +Run |
29 | 26 |
|
30 | | -Returning plain text responses |
| 27 | +Start the WebServer using: |
31 | 28 |
|
32 | | -Handling HTTP GET endpoints |
| 29 | +java -jar target/webserver-basic.jar |
33 | 30 |
|
34 | | -Using routing builders |
35 | 31 |
|
36 | | -✔ Logging Configuration |
| 32 | +The server will start on the default port (8080) unless configured otherwise. |
37 | 33 |
|
38 | | -logging.properties shows how Helidon configures Java Util Logging (JUL). |
| 34 | +Exercise the Application |
39 | 35 |
|
40 | | -✔ Tests Included |
| 36 | +After the application is running, you can call the available endpoints: |
41 | 37 |
|
42 | | -The example contains: |
| 38 | +Root endpoint |
| 39 | +curl -X GET http://localhost:8080 |
43 | 40 |
|
44 | | -Unit tests |
| 41 | +Greet endpoint |
| 42 | +curl -X GET http://localhost:8080/greet |
45 | 43 |
|
46 | | -Integration tests (running an actual WebServer instance) |
| 44 | +Personalized greeting |
| 45 | +curl -X GET http://localhost:8080/greet/{name} |
47 | 46 |
|
48 | | -These tests help verify routing behavior automatically. |
49 | 47 |
|
50 | | -▶️ How to Run |
51 | | -Using Maven |
| 48 | +This will return: |
| 49 | +{"message": "Hello {name}!"} |
52 | 50 |
|
53 | | -From the basic directory: |
| 51 | +Update the greeting |
| 52 | +curl -X PUT -H "Content-Type: application/json" \ |
| 53 | + -d '{"greeting": "Hola"}' \ |
| 54 | + http://localhost:8080/greet/greeting |
54 | 55 |
|
55 | | -mvn package |
56 | | -java -jar target/basic.jar |
| 56 | +##Notes |
57 | 57 |
|
| 58 | +This example follows the standard Helidon project layout. |
58 | 59 |
|
59 | | -Server starts on the default port (usually 8080). |
60 | | - |
61 | | -You will see output like: |
62 | | - |
63 | | -WEB server started at http://localhost:8080 |
64 | | - |
65 | | -🔗 Example Endpoints |
66 | | - |
67 | | -Once the server is running, try: |
68 | | - |
69 | | -GET /greet |
70 | | -curl http://localhost:8080/greet |
71 | | - |
72 | | - |
73 | | -Response: |
74 | | - |
75 | | -Hello World! |
76 | | - |
77 | | - |
78 | | -If routing includes path parameters, you may also test: |
79 | | - |
80 | | -GET /greet/{name} |
81 | | -curl http://localhost:8080/greet/Naveen |
82 | | - |
83 | | - |
84 | | -Example response: |
85 | | - |
86 | | -Hello Naveen! |
87 | | - |
88 | | -🧪 Run Tests |
89 | | -mvn test |
90 | | - |
91 | | - |
92 | | -This executes both: |
93 | | - |
94 | | -Unit tests |
95 | | - |
96 | | -Integration tests (start WebServer and verify responses) |
97 | | - |
98 | | -📘 Useful to Learn |
99 | | - |
100 | | -This example helps new users understand: |
101 | | - |
102 | | -How to create a minimal Helidon SE service |
103 | | - |
104 | | -How routing works |
105 | | - |
106 | | -How requests and responses are handled |
107 | | - |
108 | | -How Helidon SE applications are structured |
109 | | - |
110 | | -How to write integration tests for WebServer applications |
| 60 | +For more advanced server features, refer to other examples in the repository. |
0 commit comments