Class TeenyHttpd
java.lang.Object
net.jonathangiles.tools.teenyhttpd.TeenyHttpd
The TeenyHttpd server itself - instantiating an instance of this class and calling 'start()' is all that is required
to begin serving requests.
-
Constructor Summary
ConstructorsConstructorDescriptionTeenyHttpd(int port) Creates a single-threaded server that will work on the given port, although the server does not start until 'start()' is called.TeenyHttpd(int port, Supplier<? extends ExecutorService> executorSupplier) Creates a server that will work on the given port, although the server does not start until 'start()' is called. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFileRoute(String path, File webroot) voidaddGetRoute(String path, Function<Request, Response> handler) voidvoidaddServerSentEventRoute(String path, ServerSentEventHandler sse) voidaddStringRoute(String path, Function<Request, String> handler) static voidStarts a new server instance.voidstart()Starts the server instance.voidstop()Requests that the server instance stop serving requests.
-
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 'start()' is called.- Parameters:
port- The port for the server to listen to.
-
TeenyHttpd
Creates a server that will work on the given port, although the server does not start until 'start()' is called. The executor supplier enables creatingExecutorServiceinstances that can handle requests with a range of different threading models.- Parameters:
port- The port for the server to listen to.executorSupplier- AExecutorServiceinstances that can handle requests with a range of different threading models.
-
-
Method Details
-
main
Starts a new server instance. -
addGetRoute
-
addRoute
-
addStringRoute
-
addFileRoute
-
addServerSentEventRoute
-
start
public void start()Starts the server instance. -
stop
public void stop()Requests that the server instance stop serving requests.
-