"Hello World!" tutorials

1. Quick version!

First, we add the latest version of the org.spincast:spincast-default Maven artifact to our pom.xml (or build.gradle) :

<dependency>
    <groupId>org.spincast</groupId>
    <artifactId>spincast-default</artifactId>
    <version>2.2.0</version>
</dependency>

Then :

public class App {

    public static void main(String[] args) {
        Spincast.init(args);
    }

    @Inject
    protected void init(DefaultRouter router, Server server) {
        router.GET("/").handle(context -> context.response().sendHtml("<h1>Hello World!</h1>"));
        server.start();
    }
}

Explanation :
( Tip : try hovering/clicking the page numbers below! )

  • 3 : A standard main(...) method is the entry point of our application.
  • 4 : Spincast.init(args) will create a Guice context using the default plugins, will bind the current App class in the context and will load it.
  • 7-8 : This init method is going to be called automatically when the Guice context is ready. We inject in it the default Router and the default Server.
  • 9 : We define a Route for the index page using an inline Route Handler based on a lambda.
  • 10 : We start the server.

Try it!

Download this application, and run it by yourself :

  • Download spincast-demos-quick.zip.
  • Unzip the file.
  • Enter the root directory using a terminal.
  • Compile the application using Maven :
    mvn clean package
  • Launch the application :
    java -jar target/spincast-demos-quick-2.2.0.jar

The application is then accessible at http://localhost:44419

Too simple for you?

Try the Better... "Hello World!" demo, for an improved version!