Skip to content

This is an URL shortener service. Only the backend part is covered here. The API service can take a long URL and convert it to a shorter URL. The long URL, short URL, and other details are stored in the database. When a long URL that is already stored in the database is passed again, it returns the older shortened URL.

Notifications You must be signed in to change notification settings

Aniketsinghcoder/URL-Shortener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

URL Shortener API

This is an URL shortener service . Only the backend part is covered here. The API service can take a long URL and convert it to a shorter URL.The long URL, short URL, and other details are stored in the database. When a long URL that is already stored in the database is passed again, it returns the older shortened URL.

Run Locally

Clone the project

  git clone https://github.com/Aniketsinghcoder/URL-Shortener.git

Go to the project directory

  cd URL-Shortener

Install dependencies

  npm install

Start the server

  node app.js

API Reference

Shorten URL

  POST /api/short
Field Type Description
Body json Original Url

Example:

POST http://localhost:3333/api/short
Content-Type: application/json

{
    "origUrl": "https://www.google.com/"
}

Environment Variables

Because we have used MongoDB, we’ll need a MongoDB SRV URI. You can create a database from this link.

Now, create a .env file to store the MongoDB SRV URI and the base URL, to run this project. The base URL will be your local host server location for now. Here’s my .env file code:

MONGO_URI=mongodb+srv://username:password@cluster0.mkws3.mongodb.net/DB_NAME?retryWrites=true&w=majority
BASE=http://localhost:3333

Remember to change the <username> , <password> & <DB_NAME> field in the MongoDB URI with your database username , password & database name.

Working of REST API

WORKING_GIF

Tech Stack

NodeJS NodeJS ExpressJS ExpressJS MongoDBMongoDB

About

This is an URL shortener service. Only the backend part is covered here. The API service can take a long URL and convert it to a shorter URL. The long URL, short URL, and other details are stored in the database. When a long URL that is already stored in the database is passed again, it returns the older shortened URL.

Topics

Resources

Stars

Watchers

Forks