initial project push
32 files changed
tree: 92caaa69cb471b91f284d1a0138cb5233d14332b
  1. .gitignore
  5. api/
  6. impl/
  7. pom.xml
  8. showcase/

Peeco: an OWB centric HTTP microserver

This repository is one of the results of a GSOC 2020 (Google Summer of Code) project for OpenWebBeans at ASF. Its intention is to provide a very small and lightweight HTTP server with CDI functionalities at its core, that should hopefully become natively runnable soon, as a GraalVM native-image. For the server components, Netty is used. This repository contains the API, implementation and a showcase in the respective sub-modules.

Here's an example for how to configure and build this server:

public HttpServer init()
	return new HttpServer.Builder()
			.port(0) //applies a random valid port

And here's how you can use the API with the HttpHandler annotation:

@Inject private HttpServer httpServer;

@HttpHandler(method = {HttpMethod.GET}, url = "/hello/*", matching = Matching.WILDCARD)
public CompletionStage<Response> helloWorld(Request request)
	String responseContent = "Hello World from " + httpServer.getHost() + ":" + httpServer.getPort() + " !";
	ByteArrayInputStream output = new ByteArrayInputStream(responseContent.getBytes(StandardCharsets.UTF_8));

	return CompletableFuture.supplyAsync(() ->
		Response response = new Response();
		response.addHeader("statusCode", "200");
		response.addHeader("content-type", "text/html");
		return response;

This is a reactive example with CompletionStage; you can also straight up use Response as the method return type. The formal requirements of a valid handler method and annotation are:

  • return type must be CompletionStage<Response> or Response
  • first method parameter must be Request
  • Matching.WILDCARD needs a star at the end of the given url

For more examples please refer to the respective showcase. The implementation is found here. collects all methods that are annotated with our @HttpHandler and starts up the Netty Server. The flow of the request/response handling is then happening in