A simple implementation of shortened url in Java, Spring Boot, Postgres and Redis.
After cloning the project go to the root of the project and run:
./gradlew bootRun
The gradle will download the dependencies and start the application.
To generate a short url we should use the following instructions.
Endpoint:
POST /shortened-url/url
Request:
{
"originalUrl":"http://my-long-url",
"alias": "my-alias",
"timeToExpiration": 1636213524
}
The fields alias and timeToExpiration are optionals.
Response: 201
{
"domainApp": "http://localhost:8080/shortened-url",
"alias": "65066c97-d9e5-485f-b772-0f02e2a22171",
"shortUrl": "http://localhost:8080/shortened-url/65066c97-d9e5-485f-b772-0f02e2a22171"
}
Getting the existent short url:
Endpoint:
GET /shortened-url/url/{alias}
localhost:8080/shortened-url/url/GnYZH3O0
Response: 302
Redirect to the orignal url.
Consulting key in Redis:
127.0.0.1:6379> keys *
1) "\xac\xed\x00\x05t\x00\x03URL"
I am using Locust https://locust.io/ as a tool for loading test.
It is a tool make in Python that is very easy to use.
The script are into the folder named load-test
, so go to there and run locust
, after that, locust will start an application server to run the tests.