yet another link shortener service but purely functional.
library | version |
---|---|
cats | 2.12.0 |
cats-effect | 3.5.4 |
http4s | 0.23.27 |
skunk | 0.6.4 |
redis4cats | 1.7.0 |
circe | 0.14.8 |
weaver | 0.8.4 |
before running tests, make sure your containers running:
docker-compose up -d
use sbt test
command to run unit tests, sbt it:test
for integration tests.
instead, you can use sbt ci
alias which runs scalafmt and scalafix checker against src/{main, test, it}
then runs both cases.
after running sbt pack
, you will see there is an executable shell located in target/pack/bin/xurl
. you can easily run the application by just calling this file.
GET /_health
Returns the statuses of storage and cache services. Example response:
{
"storage": true,
"cache": true
}
GET /api/v1/urls
Returns all stored urls in database. Example response:
[
{
"code": "Fb",
"address": "https://httpbin.org/get?from=xurl2",
"hit": 0,
"created_at": "2021-12-14T16:03:00.968752"
}
]
GET /api/v1/urls/<code>
Returns the detail for a given code:
{
"code": "Fb",
"address": "https://httpbin.org/get?from=xurl2",
"hit": 0,
"created_at": "2021-12-14T16:03:00.968752"
}
POST /v1/api/urls
Shortens the given url and stores in db.
Example Request:
{
"url": "https://httpbin.org/get?from=xurl2"
}
Example Response:
{
"code": "Fb",
"address": "https://httpbin.org/get?from=xurl2",
"hit": 0,
"created_at": "2021-12-14T16:03:00.968752"
}
GET /<code>
Redirects the user to associated url for a given code.
GET /_prometheus/metrics
Exposes Prometheus-compatible JVM and server' metrics
you can access the grafana dashboard of the xurl instance by visiting http://localhost:3000
.
the grafana' default credentials have been used so you can log in with admin for username and admin for password.
the dashboard name is xurl
, you can also take a look community-driven postgres
and redis
dashboards to see metrics of them.
after building a docker image for the project by using a command like docker build . -t xurl:latest
, you should create a container using the host network since the configuration is not updated:
docker run --rm --network host xurl:latest
graalvm native image causes a bug on the metrics endpoint that are used by prometheus, the relevant endpoint somehow returns 500 for requests.