Baratine Documentation

Baratine is a service-based web server, where each service is a single reactive thread. The service architecture is designed to simplifiy writing fast and reliable applications.

Hello, World

The service can be written using annotations and Java methods. We’re using a view pattern where the service returns a string that’s written to the output by a default string view.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
import io.baratine.service.Result;
import io.baratine.web.Web;
import io.baratine.web.http.Get;

public class Hello
{
  @Get
  void hello(Result<String> result)
  {
    result.ok("Hello, world");
  }

  public static void main(String []args)
  {
    Web.args(args);

    Web.include(Hello.class);

    Web.go();
  }
}

Browsing the service at http://localhost:8080/hello will return the text. If the Result returned an object, it would be serialized to JSON.

The result.ok() at line 10 hints at Baratine’s reactive nature. The request only completes when ok() is called, not when the thread exits the method. The result lets the service call other services like a database or a message queue without needing to block the thread.

See Hello World - Eclipse/Maven for hello, world and Baratine Introduction for an introduction.