Skip to content

LeonardoSPereira/URL-Shortener

Repository files navigation

URL Shortener

Table of Contents

About

  • 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.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

What things you need to install the software and how to install them.

Installing

A step by step series of examples that tell you how to get a development env running.

  1. Clone the repository or download the zip file

  2. Install the dependencies

npm install

or

yarn install

or

pnpm install
  1. Run the database using Docker
docker-compose up -d
  1. Run the application
npm run dev

or

yarn dev

or

pnpm dev

Usage

This instructions will show you how to use the application.

Routes

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.

Create a short URL

  • Request:
POST http://localhost:3333/api/links
Content-Type: application/json
  • Body:
{
    "code": "google",
    "url": "https://www.google.com"
}
  • Response:
{
  "shortLinkId": 1
}

Access a short URL

  • 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.

Get all short URLs

  • 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"
  }
]

Get metrics of a short URL

  • Request:
GET http://localhost:3333/api/metrics
  • Response:
[
  {
    "shortLinkId": 3,
    "clicks": 9
  }
]

Technologies

About

An aplication to save your links in a shorter format

Topics

Resources

Stars

Watchers

Forks