Skip to content

Latest commit

 

History

History
100 lines (76 loc) · 2.99 KB

README.md

File metadata and controls

100 lines (76 loc) · 2.99 KB

Link Shortener API

A simple and efficient RESTful API built with Express.js to shorten, manage, and retrieve URLs. This API enables users to generate short URLs, retrieve the original URLs, and redirect to the original webpage.

Features

  • Generates an 8-character hash code for long URLs.
  • Retrieves the original URL using the short code.
  • Redirects to the original webpage using the short code.

API Reference

1. Generate Short URL

Accepts a long URL in JSON format and returns an 8-character hash code as the shortened URL.

POST /shrink
Parameter Type Description
longUrl string Required. The long URL to be shortened.

Request :

{  
  "longUrl": "https://example.com/long-url"  
}

Response :

{  
  "shortCode": "example123"  
}  

2. Retrieve Original URL

Takes an 8-character hash code as a path parameter and returns the corresponding long URL.

GET /url/:code
Parameter Type Description
url string Required. 8-character hash code of the shortened URL.

Response :

{  
  "longUrl": "https://example.com/long-url"  
}

3. Redirect to Original URL

Redirects to the original long URL corresponding to the provided 8-character hash code.

GET /visit/:code
Parameter Type Description
code string Required. The 8-character hash code of the shortened URL.

Installation and Setup

Prerequisites

Installation

1. Clone the repository :

git clone https://github.com/nirmit27/link-shrink.git

2. Navigate to the project directory :

cd link-shrink

3. Install dependencies :

npm install

Running the development server

node index.js

The API will be available at http://localhost:3000.

Tech Stack

Node.js  Express.js  MongoDB  Vercel