- This is a URL shortener service that takes a long URL and converts it into a short URL.
- The short URL is generated based on the long URL and the code that is chosen by the user.
- The short URL is stored in a database and is used to redirect the user to the long URL.
- The app uses a Redis database to store the metrics of how many times each URL has been accessed.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
What things you need to install the software and how to install them.
- Node.js
- Package Manager - npm, yarn or pnpm. I used
pnpm
in this project. - Docker
- Rest Client - Visual Studio Code Extension or any other REST client tool
A step by step series of examples that tell you how to get a development env running.
-
Clone the repository or download the zip file
-
Install the dependencies
npm install
or
yarn install
or
pnpm install
- Run the database using Docker
docker-compose up -d
- Run the application
npm run dev
or
yarn dev
or
pnpm dev
This instructions will show you how to use the application.
If you are using Visual Studio Code, you can use the Rest Client extension to test the routes. To do this, just open the requests.http
file and click on the Send Request
button that appears on the right side of the route.
- Request:
POST http://localhost:3333/api/links
Content-Type: application/json
- Body:
{
"code": "google",
"url": "https://www.google.com"
}
- Response:
{
"shortLinkId": 1
}
- Request:
GET http://localhost:3333/:code
-
Parameters:
code
: The code of the short URL
-
Response: The user will be redirected to the long URL. If you're using the REST Client, you can see the page HTML in the response body. If you're using a browser, you will be redirected to the long URL.
- Request:
GET http://localhost:3333/api/links
- Response:
[
{
"id": 1,
"code": "google",
"original_url": "https://www.google.com",
"created_at": "2024-03-20T16:22:20.428Z"
}
]
- Request:
GET http://localhost:3333/api/metrics
- Response:
[
{
"shortLinkId": 3,
"clicks": 9
}
]