Code Monkey home page Code Monkey logo

short-link's Introduction

ShortLink

Introduction

ShortLink is a simple project that allows the shortening of long URLs into more manageable links. This API is built with JavaScript and provides endpoints for shortening URLs, retrieving original URLs from shortened links, statistics tracking and redirecting generated links to the originals.

Features

  • Shorten long URLs into shorter, more manageable links.
  • Retrieve original URLs from shortened links.
  • Track statistics such as the number of visits for each shortened link.

Prerequisites

Node version >=12.0.0 and npm or yarn installed on your machine.

Installation

1. Clone this repository:

git clone https://github.com/tdogubo/short-link.git

2. Navigate to project directory:

cd short-link

3. Install dependencies:

Using Yarn

yarn install

Using npm

npm install

Usage

  1. Start the server
yarn start
  1. The API will be available at http://localhost:3001 by default.

  2. Use the following endpoints to interact with the API:

  • POST /v1/urls/encode: Shorten a long URL. Provide the long URL in the request body.
  • POST /v1/urls/decode: Retrieve the original URL associated with a shortened link.
  • GET /v1/urls/:id/statics: Retrieve statistics for a shortened link, such as the number of visits.
  • GET /:id : Redirects to the original link and increments the visited field of the url.

Example

1. Shorten URL

curl -H 'Content-Type: application/json' \
      -d '{"url": "https://example.com/"}' \
      -X POST \
      http://localhost:3001/v1/urls/encode

Response

{
    "data": {
        "original": "http://localhost:3001/Dz1dmlFKgZ"
    }
}

2. Retrieve Original URL

curl -H 'Content-Type: application/json' \
      -d '{"url": "http://localhost:3001/Dz1dmlFKgZ"}' \
      -X POST \
      http://localhost:3001/v1/urls/decode

Response

{
    "data": {
        "original": "https://example.com/"
    }
}

3. Get Stats on a URL

curl http://localhost:3001/v1/urls/Dz1dmlFKgZ/statics

Response

{
    "data": {
        "id": "Dz1dmlFKgZ",
        "originalUrl": "https://example.com/",
        "shortUrl": "http://localhost:3001/Dz1dmlFKgZ",
        "visited": 0,
        "createdAt": "2024-03-27T23:06:45.891Z"
    }
}

4. To visit a url paste generated link in browser while server is still running.

short-link's People

Contributors

tdogubo avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.