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.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTeenyHttpd(int port) Creates a single-threaded server that will work on the given port, although the server does not start until 'stort()' 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 'stort()' is called. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFileRoute(String path) voidaddFileRoute(String path, File webroot) voidaddGetRoute(String path, Function<Request, Response> handler) voidvoidaddStringRoute(String path, Function<Request, String> handler) static voidStarts a new server instance on port 80, and serves requests from the current working directory.voidstart()Starts the server instance.voidstop()Requests that the server instance stop serving requests.
-
Field Details
-
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
Creates a server that will work on the given port, although the server does not start until 'stort()' 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 on port 80, and serves requests from the current working directory. -
addGetRoute
-
addRoute
-
addStringRoute
-
addFileRoute
-
addFileRoute
-
start
public void start()Starts the server instance. -
stop
public void stop()Requests that the server instance stop serving requests.
-