- Make sure that both Java 17, The Maven package manager, and Docker with Compose are installed.
- Copy the
.env.sample
into a new file called.env
and fill in the values. There are defaults setup but creating the.env
file will allow for customization. Both the application and the docker container will use the values.- The
POSTGRES_DB
is used for the name of the database. Default isurl_shortener
. - The
POSTGRES_PASSWORD
is used for postgres user password. Default ispostgres
. - The
POSTGRES_PORT
is used for port to bind postgres to. Default is5432
. - The
POSTGRES_USER
is used for the postgres user. Default ispostgres
.
- The
- Make sure you have navigated to the root of the project
- Run the command
docker compose up -d
to start docker. - Run the command
./mvnw spring-boot:run
to start the application. The application will listen on port8080
.
- Run the command
./mvnw test
to run all tests.
NOTE: The application does not need to be running when running tests. The integration tests will run with an embedded database so the test data should not be reflected in the local database.
Make a POST
request to http://localhost:8080/short-urls
with body:
{
"destination": "<destination_url>"
}
Sample response:
{
"id": "037284f8-6f94-4a74-8476-f962c360e38f",
"code": "WRRgU",
"destination": "https://loremflickr.com/320/240",
"createdAt": "2022-05-23T09:20:40.269425499-04:00",
"updatedAt": "2022-05-23T09:20:40.269730937-04:00"
}
Make a GET
request to http://localhost:8080/<code>
Make a GET
request to http://localhost:8080/clicks/<code>
Sample Response:
{
"count": 2,
"page": 0,
"total": 2,
"clicks": [
{
"id": "7c1548e5-02b6-4c19-95c2-7b01e7d6112d",
"clickedAt": "2022-05-22T23:22:55.375493-04:00",
"shortCodeClicked": "nsur7"
},
{
"id": "661ade8e-dd30-4210-b85b-150ef6e50541",
"clickedAt": "2022-05-22T23:22:57.780271-04:00",
"shortCodeClicked": "nsur7"
}
]
}
There are also two accepted query params page
and size
for the this paginated route.
Sample Request: http://localhost:8080/clicks/<code>?page=0&size=3
Sample Response:
{
"count": 3,
"page": 0,
"total": 22,
"clicks": [
{
"id": "ecf12758-7557-41d6-8c7f-6fa7a9de116d",
"clickedAt": "2022-05-22T23:20:17.416597-04:00",
"shortCodeClicked": "WRRgU"
},
{
"id": "640b1300-505f-44e5-a4f7-c3717c522a40",
"clickedAt": "2022-05-22T23:21:29.855056-04:00",
"shortCodeClicked": "WRRgU"
},
{
"id": "e5c2d403-07f3-4efe-81f3-3aa71cabaa80",
"clickedAt": "2022-05-22T23:21:37.035355-04:00",
"shortCodeClicked": "WRRgU"
}
]
}