HTTP service template with Leiningen.
Building and running the http service using the lein project tools.
The standalone uberjar can be built with lein and run with the java -jar command.
Build the uberjar
lein uberjar
-
Export environment variables for server settings if wanting to override defaults.
Example
# Port the http-server will listen on (default: 8080) export HTTP_PORT=8000
-
Run the http-server
-
With lein
lein run
-
With the built uberjar
java -jar target/uberjar/http-service-lein-1.0.0-standalone.jar
-
Building and running the http service with docker.
The docker image is built and tagged by running:
make build
Different ways to run the development/testing container.
-
Run an interactive container.
- control+c to stop/remove the container.
make docker-run
-
Run a container and connect with a shell.
- Type "exit" to stop/remove the container.
make shell
-
Run a container in detached mode.
- Stop the container using "docker stop
CONTAINER ID
". It will be deleted upon stop.
make docker-run-detach
- Stop the container using "docker stop
Send client requests to the running http-server.
Available default routes are:
- GET /help -> return plain text help.
- GET /healthy -> return json of the health check response.
Example output using httpie.
help
http http://localhost:8080/help
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Date: Fri, 26 Jan 2024 02:19:36 GMT
Server: http-kit
content-length: 140
HTTP API (1.0.0). Send requests to:
GET /help -> This help dialog.
GET /healthy -> Application health check.
healthy
http http://localhost:8080/healthy
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Date: Fri, 26 Jan 2024 02:26:14 GMT
Server: http-kit
content-length: 16
{
"healthy": true
}
Copyright © 2021-2024 Bill Howe
This program and the accompanying materials are made available under the
terms of the Eclipse Public License 2.0 which is available at
http://www.eclipse.org/legal/epl-2.0.
This Source Code may also be made available under the following Secondary
Licenses when the conditions for such availability set forth in the Eclipse
Public License, v. 2.0 are satisfied: GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or (at your
option) any later version, with the GNU Classpath Exception which is available
at https://www.gnu.org/software/classpath/license.html
.