This is a clojure microservice template: Components, Reitit, Pedestal, Malli, Postgresql and Tests.
-
template: An example of how use the template, it's a simple job post api, which you can create, list all or list one job by id.
-
common/components: Foundation to create new services in clojure, you can find components for database, http, webserver and tools for db migrations.
| Verb | URL | Description |
|---|---|---|
| GET | /job/ | get all job |
| POST | /job/ | create a new job post |
| GET | /job/:id | get the job by id |
./
├── .clj-kondo -- clj-kondo configuration and classes
├── .lsp -- clojure-lsp configuration
├── .github
│ └── workflows -- Github workflows folder.
├── docker -- docker and docker-compose files for the database
├── resources -- Application resources assets folder and configuration files.
│ └── migrations -- Current database schemas, synced on service startup.
│ └── config.edn -- Application config.
├── src -- Library source code and headers.
│ └── io/easybootstrap/template -- Source for the service example job template.
└── test -- Test source code.
├── integration -- Integration tests source (uses state-flow).
│ └── io/easybootstrap/template/ -- Tests for service integration.
└── unit -- Unity tests source (uses clojure.test).
└── io/easybootstrap/template/ -- Tests for service unit.
To open a nrepl
clj -M:nreplTo open a nrepl with all test extra-deps on it
clj -M:test:nreplTo open a dev nrepl
clj -M:dev:nreplThen go to dev/user.clj and eval (start)
To run unit tests inside ./test/unit
clj -M:test :unitTo run integration tests inside ./test/integration
clj -M:test :integrationTo run all tests inside ./test
clj -M:testTo generate a coverage report
clj -M:test --plugin kaocha.plugin/cloverage
|----------------------------------------------------+---------+---------|
| Namespace | % Forms | % Lines |
|----------------------------------------------------+---------+---------|
| io.easybootstrap.template.adapters.job | 65.71 | 61.54 |
| io.easybootstrap.template.controllers.job | 100.00 | 100.00 |
| io.easybootstrap.template.mediator.db.postgres.job | 100.00 | 100.00 |
| io.easybootstrap.template.mediator.http-in | 100.00 | 100.00 |
| io.easybootstrap.template.server | 14.93 | 31.82 |
| io.easybootstrap.template.wire.common | 100.00 | 100.00 |
| io.easybootstrap.template.wire.db.job | 100.00 | 100.00 |
| io.easybootstrap.template.wire.in.job | 100.00 | 100.00 |
| io.easybootstrap.template.wire.out.job | 100.00 | 100.00 |
|----------------------------------------------------+---------+---------|
| ALL FILES | 84.42 | 86.58 |clj -M:clojure-lsp format
clj -M:clojure-lsp clean-ns
clj -M:clojure-lsp diagnosticsTo create a new migration with a name
clj -M:migratus create migration-nameTo execute all pending migrations
clj -M:migratus migrateTo rollback the latest migration
clj -M:migratus rollbackSee Migratus Usage for documentation on each command.
Start containers with postgres user: postgres, password: postgres, hostname: db, port: 5432
and pg-admin email: pg@pg.cc, password: pg, port: 5433
docker-compose -f docker/docker-compose.yml up -dStop containers
docker-compose -f docker/docker-compose.yml stopFirst you need to have the database running, for this you can use the docker command in the step above.
You can start a repl open and evaluate the file src/microservice_boilerplate/server.clj and execute following code:
(start-system! (build-system-map))You can generate an uberjar and execute it via java in the terminal:
# genarate a target/service.jar
clj -T:build uberjar
# execute it via java
java -jar target/service.jarBased on this
This is free and unencumbered software released into the public domain.
For more information, please refer to http://unlicense.org