Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/amanmalviya22/url-shortener-api
https://github.com/amanmalviya22/url-shortener-api
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/amanmalviya22/url-shortener-api
- Owner: AmanMalviya22
- Created: 2024-07-09T08:18:25.000Z (6 months ago)
- Default Branch: master
- Last Pushed: 2024-07-09T08:50:32.000Z (6 months ago)
- Last Synced: 2024-07-10T11:07:18.735Z (6 months ago)
- Language: JavaScript
- Size: 314 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# URL Shortener API
This project implements a powerful URL shortener API with advanced analytics capabilities using Node.js, Express, MongoDB, Redis, and Bull for background jobs.
## Table of Contents
- [Introduction](#introduction)
- [Features](#features)
- [Getting Started](#getting-started)
- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
- [Endpoints](#endpoints)
- [Request and Response Formats](#request-and-response-formats)
- [Advanced Features](#advanced-features)
- [Custom Short Codes](#custom-short-codes)
- [URL Expiration](#url-expiration)
- [Rate Limiting](#rate-limiting)
- [Background Jobs](#background-jobs)
- [Database Schema](#database-schema)
- [Contributing](#contributing)
- [License](#license)## Introduction
This API provides functionalities to shorten URLs, track visits with detailed analytics, and manage shortened links efficiently. It supports custom short codes, URL expiration, rate limiting, and background jobs for asynchronous tasks.
## Features
- **URL Shortening:** Shorten long URLs to compact forms.
- **Advanced Tracking:** Track visits with timestamp, user agent, IP address, and device type.
- **Analytics:** Retrieve detailed analytics including total visits, unique visitors, visits by device type, and more.
- **Custom Short Codes:** Allow users to specify custom short codes for URLs.
- **URL Expiration:** Implement URL expiration after a specified time.
- **Rate Limiting:** Prevent abuse with rate limits for URL shortening requests.
- **Background Jobs:** Use Bull for handling background tasks such as visit data aggregation.## Getting Started
### Prerequisites
- Node.js
- MongoDB
- Redis### Installation
1. **Clone the repository:**
```bash
git clone https://github.com/AmanMalviya22/url-shortener-api.git
cd url-shortener-api2. **Install dependencies:**
```bash
npm install3. **Configuration:**
```bash
Set up environment variables:
Create a .env file and configure MongoDB and Redis connection details.
PORT=3000
MONGO_URI=mongodb://localhost:27017/urlshortener
REDIS_URL=redis://localhost:63794. **go to redis intallation directory and run redis-server.exe:**
5. **in vs code terminal type npm start, it will start your application.**
6. **Now open postman and test the application using below instruction.**
## Endpoints
```bash
POST localhost:3000/api/shorten: Shorten a URL.
GET localhost:3000/api/:shortCode: Redirect to the original URL and track visit.
GET localhost:3000/api/analytics/:shortCode: Retrieve analytics for a shortened URL## Request and Response Formats : Refer these postman screenshot
1. For Generating Short URL
![alt text](image.png)2. Testing the Short URL
![alt text](image-1.png)3. Analytics of Short URL
![alt text](image-2.png)## Advanced Features
# Custom Short Codes
Users can specify custom short codes during URL shortening. The API checks for uniqueness and handles conflicts.# URL Expiration
Shortened URLs can be set to expire after a configurable time. Expired URLs are no longer accessible.# Rate Limiting
API endpoints are protected with rate limiting to prevent abuse. Limits are enforced based on user, IP address, and custom short code creation.# Background Jobs
The API utilizes Bull for handling background jobs such as visit data aggregation for analytics reports.