Skip to content

The fuel that'll ignite your application. A programmable TLS HTTP/1.1 server with no dependencies.

License

Notifications You must be signed in to change notification settings

Kerosene-Labs/kindling

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kindling

The fuel that'll ignite your application.

A programmable TLS HTTP/1.1 server written with no dependencies.

Key Features

  • SSL/TLS only (using SSLServerSocket)
  • No magic with visible control flow
  • Light weight
  • No Dependencies
  • Virtual Threads

Example

Below is an example implementation of a Kindling Server with a simple request handler that responds with a JSON object to a GET request on the / resource.

public class Main {
    public static void main(String[] args) throws KindlingException {

        KindlingServer server = KindlingServer.getInstance();

        // test request handler
        server.installRequestHandler(new RequestHandler() {
            /**
             * Tell the server what type of request this handler can work with
             */
            @Override
            public boolean accepts(HttpRequest httpRequest) throws KindlingException {
                return httpRequest.getHttpMethod().equals(HttpMethod.GET) && httpRequest.getResource().equals("/");
            }

            /**
             * Do your business logic here
             */
            @Override
            public HttpResponse handle(HttpRequest httpRequest) throws KindlingException {
                return new HttpResponse.Builder()
                        .status(HttpStatus.OK)
                        .contentType(MimeType.APPLICATION_JSON)
                        .content("{\"key\": \"value\"}")
                        .build();
            }
        });

        // serve our server
        server.serve(8443, Path.of("keystore.p12"), "password");
    }
}

Let's break down the components above.

  • KindlingServer
    • The singleton that contains the application context
    • Manages the SSLServerSocket and the virtual thread that is assigned to each request
  • RequestHandler
    • Accepts
      • Called when a request is received
      • Return a boolean telling the server if we can handle this request
    • Handle
      • If the accepts() method returns true, handle() is called
      • Do your business logic here, returning an HttpResponse
  • Server Serve
    • Start serving the SSLServerSocket on the provided port with the given P12 keystore

About

The fuel that'll ignite your application. A programmable TLS HTTP/1.1 server with no dependencies.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages