The intent of this project is to familiarize myself with Clojure. Not only the language, but also the development process.
- Start docker
docker compose up -d
- Run
make run
- It will run on
localhost:3000
In deps.edn
there is an alias dev
that allow to run the application and interacts with XTDB.
Start the REPL with the dev
alias and run:
(start)
It will start the server on port 3000
and hot-reload. However, the hot reload doesn't not work so well so some changes require restarting the REPL.
To stop the server, run:
(stop)
Also, you can interact with the XTDB node using
xt/submit-tx
and xt/q
. They are already imported in the namespace and there is a global node
.
Querying all TODOs:
(xt/q node '(from :todos [*]))
This API is composed of the following endpoints:
GET /todos
GET /todos/:id
POST /todos
DELETE /todos/:id
PATCH /todos/:id
An TODO object looks like:
{
"description": "my description",
"completed": false,
"title": "My task 2",
"xt/id": "d57087f9-a23f-4e0c-bc9b-1e166dcf75c1"
}
It excepts a payload with title
and description
:
{
"title": "My task 5",
"description": "my description"
}
It creates an object in the todos
table with completed = false
and random UUID to xt/id
This endpoint allow to update the title
, description
, and the completed
flag:
{
"completed": false,
"title": "My new task title",
"description": "My new task description"
}
I opted for deps.edn
over lein
to keep things simple. Lein reminds me a lot of Java projects and after having great DX with Node ecosystem, I want things at least simple.
Using Compojure because seems the most straightforward way of building web applications. However, the reload on file change was tricky to make it work. ring.middleware.reload
favors variable references and I didn' want to have global variables.
XTDB v2 was used only because of XTQL. I could manage to do all operations with it instead SQL.