///////////////////////////////////////////////////////////////////////////////

    Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.

    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.

///////////////////////////////////////////////////////////////////////////////

= MicroProfile Introduction
:description: Helidon MicroProfile introduction
:keywords: helidon, microprofile, micro-profile

MicroProfile is a collection of enterprise Java APIs that should feel familiar to
Java EE developers. MicroProfile includes existing APIs such as JAX-RS, JSON-P and
CDI, and adds additional APIs in areas such as configuration, metrics, fault
tolerance and more.

== Getting Started with Helidon MicroProfile

Helidon MP {helidon-version} supports
MicroProfile {mp-version}. You can find the exact version of APIs supported on the
https://github.com/oracle/helidon/wiki/Supported-APIs[Helidon Supported APIs]
wiki page.

Helidon provides a MicroProfile server implementation (`io.helidon.microprofile.server`) that
encapsulates the Helidon WebServer. You can either instantiate the server directly
as is done in the
<<guides/03_quickstart-mp.adoc, Helidon MP Quickstart example>>
or use its built-in `main` as shown below.

Complete these tasks to get started with your MicroProfile application.

=== 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]
.Maven Dependency for full MicroProfile
----
<dependency>
  <groupId>io.helidon.microprofile.bundles</groupId>
  <artifactId>helidon-microprofile</artifactId>
</dependency>
----

The above dependency adds all the features available in MicroProfile. If you
want to start with a smaller core set of features then you can use the
`core` bundle instead. This bundle includes the base feature in MicroProfile
(such as JAX-RS, CDI, JSON-P/B, and Config) and leaves out some of the
additional features such as Metrics and Tracing. You can add those dependencies
individually if you choose.

[source,xml]
.Maven Dependency for MicroProfile core features only
----
<dependency>
  <groupId>io.helidon.microprofile.bundles</groupId>
  <artifactId>helidon-microprofile-core</artifactId>
</dependency>
----

=== Project files

Create a JAX-RS Resource class with at least one resource method.

[source,java]
.Sample JAX-RS Resource Class
----
@Path("/")
@RequestScoped
public class HelloWorldResource {
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String message() {
        return "Hello World";
    }
}
----

And create a JAX-RS application.
[source,java]
.Sample JAX-RS Application
----
@ApplicationScoped
@ApplicationPath("/")
public class HelloWorldApplication extends Application {
    @Override
    public Set<Class<?>> getClasses() {
        return Set.of(
                HelloWorldResource.class
        );
    }
}
----

Add `beans.xml` in `src/main/resources/META-INF` so
the CDI implementation can pick up your classes.
[source,xml]
.beans.xml
----
<?xml version="1.0" encoding="UTF-8"?>
<beans/>
----

As a last step, add a main method to your application (or a dedicated Main class)
 to start everything up.

[source,java]
.Sample JAX-RS Application
----
public static void main(String[] args) {
    io.helidon.microprofile.server.Main.main(args);
}
----

Run the main class. The server will start on port 7001 and serve your
 resources.

=== Adding Jandex

Jandex is an indexing tool for Weld (the CDI implementation used by Helidon) that helps speed up
the boot time of an application.

To use Jandex, configure a Maven plugin that adds the index to your
 JAR file and a dependency on Jandex.

[source,xml]
.jandex dependency
----
<dependency>
    <groupId>org.jboss</groupId>
    <artifactId>jandex</artifactId>
    <version>2.0.4.Final</version>
</dependency>
----

[source,xml]
.jandex plugin configuration
----
<build>
    <plugins>
        <plugin>
            <groupId>org.jboss.jandex</groupId>
            <artifactId>jandex-maven-plugin</artifactId>
            <version>1.0.5</version>
            <executions>
                <execution>
                    <id>make-index</id>
                    <goals>
                        <goal>jandex</goal>
                    </goals>
                    <phase>process-classes</phase>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
----
