Package com.renomad.minum.web


package com.renomad.minum.web
This package provides HTTP capabilities.

Most valuable for those new to Minum:

  1. WebFramework - Provides methods to register endpoints
  2. The IRequest interface for HTTP requests, primarily the request line (including query strings), headers, and body
  3. The Response class, which provides methods to build an HTTP response
  4. The FullSystem class, providing access to whole-system state

Most other classes provide capabilities to branch off those core concepts.

Here is a typical "main" method for an application. We initialize FullSystem, which constructs necessary state and starts socket listeners for the TLS and non-encrypted servers. We then use the WebFramework object to register endpoints. A more organized approach is to put the endpoint registrations into another file. An example is "TheRegister.java", in the test directory.

 
 package org.example;

 import com.renomad.minum.web.FullSystem;
 import com.renomad.minum.web.Response;

 import static com.renomad.minum.web.RequestLine.Method.GET;

 public class Main {

     public static void main(String[] args) {
         FullSystem fs = FullSystem.initialize();
         fs.getWebFramework().registerPath(GET, "", request -> Response.htmlOk("<p>Hi there world!</p>"));
         fs.block();
     }
 }
 
 

Here's an example of a business-related function using authentication and the Minum database. This code is extracted from the SampleDomain.java file in the src/test directory:


       public IResponse formEntry(IRequest r) {
         final var authResult = auth.processAuth(r);
         if (! authResult.isAuthenticated()) {
             return Response.buildLeanResponse(CODE_401_UNAUTHORIZED);
         }
         final String names = db
                 .values().stream().sorted(Comparator.comparingLong(PersonName::getIndex))
                 .map(x -> "<li>" + StringUtils.safeHtml(x.getFullname()) + "</li>\n")
                 .collect(Collectors.joining());

         return Response.htmlOk(nameEntryTemplate.renderTemplate(Map.of("names", names)));
     }