Skip to content

Hello World

Alexander Söderberg edited this page Nov 15, 2017 · 7 revisions

Hello... world?

What would a wiki be, without a 'Hello World!' example? Rhetorical questions aside, this is how you achieve the outputting of such marvelous text in Kvantum:

First you'll need to add Kvantum as a dependency to your project. We recommend using either Gradle or Maven, but it's entirely up to you. If you need help doing that, then you can read Getting Started

Secondly, you'll need to create your own launcher class. Everything after that point depends on your needs.

package your.package;

import com.github.intellectualsites.kvantum.api.core.Kvantum;
import com.github.intellectualsites.kvantum.api.util.RequestManager;

import java.io.File;
import java.util.Optional;


public class HelloWorld
{

    public static void main(final String[] args)
    {
        final ServerContext serverContext = ServerContext.builder()
                .standalone( true )
                .coreFolder( new File( "./HelloWorld" ) )
                .logWrapper( new DefaultLogWrapper() )
                .router( RequestManager.builder().build() ).build();

        final Optional<Kvantum> serverOptional = serverContext.create();

        if ( !serverOptional.isPresent() )
        {
            System.out.println( "Failed to start the server... Check terminal for information!" );
            System.exit( -1 );
        }
        else
        {
            final Kvantum server = serverOptional.get();
            server.createSimpleRequestHandler( "[file]", (request, response) -> response.setContent( "Hello World!" ) );
            server.start();
        }
    }

}

Link to source file

This is just one of the methods you can use to generate a response via code. There is also an annotation-based system, and a OOP approach if that's more your style. We have tried to make the whole system as unlimited as possible, to suit every programmer and their preferred coding styles.

Navigation

Templates

Configuration

Files can be found in .kvantum/config

Views

/commands

Development

Clone this wiki locally