mirror of
https://github.com/jlengrand/helidon.git
synced 2026-03-10 08:21:17 +00:00
65 lines
2.3 KiB
Plaintext
65 lines
2.3 KiB
Plaintext
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
Copyright (c) 2018, 2020 Oracle and/or its affiliates.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
= WebServer Introduction
|
|
:h1Prefix: SE
|
|
:pagename: webserver-introduction
|
|
:description: Helidon Reactive WebServer Introduction
|
|
:keywords: helidon, reactive, reactive streams, reactive java, reactive webserver
|
|
|
|
WebServer provides an asynchronous and reactive API for creating web applications.
|
|
The API is inspired by popular NodeJS and Java frameworks.
|
|
|
|
== Quick Start
|
|
|
|
Here is the code for a minimalist web application that runs on a random free port:
|
|
|
|
[source,java]
|
|
----
|
|
public static void main(String[] args) {
|
|
WebServer webServer = WebServer
|
|
.create(Routing.builder()
|
|
.any((req, res) -> res.send("It works!"))) // <1>
|
|
.start() // <2>
|
|
.await(10, TimeUnit.SECONDS); // <3>
|
|
|
|
System.out.println("Server started at: http://localhost:" + webServer.port()); // <4>
|
|
}
|
|
----
|
|
|
|
<1> For any kind of request, at any path, respond with `It works!`.
|
|
<2> Start the server.
|
|
<3> Wait for the server to start while throwing possible errors as runtime exceptions.
|
|
<4> The server is bound to a random free port.
|
|
|
|
== Maven Coordinates
|
|
|
|
The <<about/04_managing-dependencies.adoc, Managing Dependencies>> page describes how you
|
|
should declare dependency management for Helidon applications.
|
|
Then declare the following dependency in your project:
|
|
|
|
[source,xml,subs="verbatim,attributes"]
|
|
----
|
|
<dependency>
|
|
<groupId>io.helidon.webserver</groupId>
|
|
<artifactId>helidon-webserver</artifactId> <!--1-->
|
|
</dependency>
|
|
----
|
|
|
|
<1> Dependency on WebServer.
|