<chapter id="Se_Bootstrap">
    <title>&REST-API; SeBootstrap</title>
    <para>
        In &REST-API; 3.1 the new <classname>jakarta.ws.rs.SeBootstrap</classname> API was introduced to run
        &REST-API; applications in a Java SE environment. As an implementation of the specification RESTEasy includes
        an implementation for this API.
    </para>
    <section id="sebootstrap-overview">
        <title>Overview</title>
        <para>
            It&apos;s suggested by default that the <code>org.jboss.resteasy:resteasy-undertow-cdi</code> implementation be
            used. However, the other <classname>org.jboss.resteasy.plugins.server.embedded.EmbeddedServer</classname>
            will work excluding the <code>org.jboss.resteasy:resteasy-jdk-http</code>.
        </para>
        <para>
            The <code>org.jboss.resteasy:resteasy-undertow-cdi</code> implementation also uses Weld to create a CDI
            container. This allows the CDI in the SE environment to be used. If CDI is not required or desired the
            <code>org.jboss.resteasy:resteasy-undertow</code> implementation could be used instead.
        </para>
        <para>
            Example POM Dependencies:
            <programlisting>
&lt;dependencies&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;jakarta.ws.rs&lt;/groupId&gt;
        &lt;artifactId&gt;jakarta.ws.rs-api&lt;/artifactId&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
        &lt;artifactId&gt;resteasy-core&lt;/artifactId&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
        &lt;artifactId&gt;resteasy-client&lt;/artifactId&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
        &lt;artifactId&gt;resteasy-undertow-cdi&lt;/artifactId&gt;
    &lt;/dependency&gt;
&lt;/dependencies&gt;
            </programlisting>
        </para>
        <para>
            It&apos;s also suggested that if the resources to be used in the application are not explicitly define,
            then use the <code>org.jboss.jandex:jandex-maven-plugin</code> to create a Jandex Index. Without this
            the class path will be scanned for resources which could have significant performance impacts.
            <programlisting>
&lt;plugin&gt;
    &lt;groupId&gt;org.jboss.jandex&lt;/groupId&gt;
    &lt;artifactId&gt;jandex-maven-plugin&lt;/artifactId&gt;
    &lt;executions&gt;
        &lt;execution&gt;
            &lt;id&gt;make-index&lt;/id&gt;
            &lt;goals&gt;
                &lt;goal&gt;jandex&lt;/goal&gt;
            &lt;/goals&gt;
        &lt;/execution&gt;
    &lt;/executions&gt;
&lt;/plugin&gt;
            </programlisting>
        </para>
    </section>
    <section id="sebootstrap-usage">
        <title>Usage</title>
        <para>
            Example of using the <classname>jakarta.ws.rs.SeBootstrap</classname> API:
            <programlisting>
SeBootstrap.start(ExampleApplication.class, SeBootstrap.Configuration.builder()
                .build())
        .thenApply((instance) -> {
            try (Client client = ClientBuilder.newClient()) {
                final WebTarget target = client.target(instance.configuration().baseUriBuilder());
                final Response response = client.target(instance.configuration()
                                .baseUriBuilder()
                                .path("/api/product/widget"))
                        .request()
                        .get();
                System.out.printf("Response: %d - %s%n", response.getStatus(), response.readEntity(String.class));
            }
            return instance;
        })
        .whenComplete((instance, t) -> instance.stop());
            </programlisting>
        </para>
    </section>
    <section id="sebootstrap-config-options">
        <title>Configuration Options</title>
        <para>
            Configuration options are represented by the <classname>org.jboss.resteasy.core.se.ConfigurationOption</classname>
            enum. This enum includes all the supported configuration options.
            <programlisting>
final SeBootstrap.Configuration configuration = SeBootstrap.Configuration.builder()
        .port(8443)
        .protocol("HTTPS")
        .property(ConfigurationOption.JANDEX_CLASS_PATH_FILTER.key(), Index.of(ItemResource.class, OrderResource.class));
            </programlisting>
        </para>
    </section>
</chapter>