java.lang.Object
net.jonathangiles.tools.teenyhttpd.TeenyHttpd

public class TeenyHttpd extends Object
The TeenyHttpd server itself - instantiating an instance of this class and calling 'start()' is all that is required to begin serving requests.
  • Field Details

    • DEFAULT_WEB_ROOT

      public static final File DEFAULT_WEB_ROOT
  • Constructor Details

    • TeenyHttpd

      public TeenyHttpd(int port)
      Creates a single-threaded server that will work on the given port, although the server does not start until 'stort()' is called.
      Parameters:
      port - The port for the server to listen to.
    • TeenyHttpd

      public TeenyHttpd(int port, Supplier<? extends ExecutorService> executorSupplier)
      Creates a server that will work on the given port, although the server does not start until 'stort()' is called. The executor supplier enables creating ExecutorService instances that can handle requests with a range of different threading models.
      Parameters:
      port - The port for the server to listen to.
      executorSupplier - A ExecutorService instances that can handle requests with a range of different threading models.
  • Method Details

    • addGetRoute

      public void addGetRoute(String path, Function<Request,Response> handler)
    • addRoute

      public void addRoute(Method method, String path, Function<Request,Response> handler)
    • addStringRoute

      public void addStringRoute(String path, Function<Request,String> handler)
    • addFileRoute

      public void addFileRoute(String path)
    • addFileRoute

      public void addFileRoute(String path, File webroot)
    • start

      public void start()
      Starts the server instance.
    • stop

      public void stop()
      Requests that the server instance stop serving requests.