https://github.com/nirmit27/link-shrink
A RESTful API for shortening long URLs built using Express and MongoDB.
https://github.com/nirmit27/link-shrink
api api-rest crypto express express-middleware expressjs link-shortener link-shortener-api link-shortener-backend link-shortener-server mongodb mongodb-atlas node-crypto
Last synced: 3 months ago
JSON representation
A RESTful API for shortening long URLs built using Express and MongoDB.
- Host: GitHub
- URL: https://github.com/nirmit27/link-shrink
- Owner: nirmit27
- Created: 2024-09-07T12:44:56.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-12-05T17:12:47.000Z (over 1 year ago)
- Last Synced: 2025-01-08T18:16:02.459Z (over 1 year ago)
- Topics: api, api-rest, crypto, express, express-middleware, expressjs, link-shortener, link-shortener-api, link-shortener-backend, link-shortener-server, mongodb, mongodb-atlas, node-crypto
- Language: JavaScript
- Homepage:
- Size: 320 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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.
```http
POST /shrink
```
| Parameter | Type | Description |
| :-------- | :------- | :------------------------------------------ |
| `longUrl` | `string` | **Required.** The long URL to be shortened. |
**Request :**
```json
{
"longUrl": "https://example.com/long-url"
}
```
**Response :**
```json
{
"shortCode": "example123"
}
```
### 2. Retrieve Original URL
Takes an 8-character hash code as a **path** parameter and returns the corresponding long URL.
```http
GET /url/:code
```
| Parameter | Type | Description |
| :-------- | :------- | :-------------------------------------------------------- |
| `url` | `string` | **Required.** 8-character hash code of the shortened URL. |
**Response :**
```json
{
"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.
```http
GET /visit/:code
```
| Parameter | Type | Description |
| :-------- | :------- | :------------------------------------------------------------ |
| `code` | `string` | **Required.** The 8-character hash code of the shortened URL. |
## Installation and Setup
### Prerequisites
- [Node.js](https://nodejs.org/en/download)
- [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) or [yarn](https://classic.yarnpkg.com/lang/en/docs/install/#windows-stable)
### Installation
#### 1. Clone the repository :
```bash
git clone https://github.com/nirmit27/link-shrink.git
```
#### 2. Navigate to the project directory :
```bash
cd link-shrink
```
#### 3. Install dependencies :
```bash
npm install
```
#### Running the development server
```bash
node index.js
```
The **API** will be available at http://localhost:3000.
## Tech Stack
[](https://nodejs.org/en)
[](https://expressjs.com/)
[](https://www.mongodb.com/)
[](https://vercel.com/)