Skip to content

mayank-aggrwal/URL-shortener

Repository files navigation

💻 SHORTT-LY (URL-Shortener)

A simple yet useful web service to compress long URLs into shorter ones.

Features

  1. General URL shortening
  2. Custom URL shortening
  3. Easy to integrate with other applications

Open Endpoints

  • Shorten given long URL : POST /api/short
  • Shorten URL with custom code : POST /api/custom
  • Redirect to website : GET /:code
  • Check API health : GET /health

POST /api/short

Request schema

{
    "longUrl": "<the-long-url-to-be-shortened>"
}

Response schema

{
  "_id": "5f81dca70f685f2f104",
  "longUrl": "<the-long-url-to-be-shortened>",
  "shortUrl": "https://<base-url>/-i8bZ5O9B",
  "urlCode": "-i8bZ5O9B",
  "date": "Sat Oct 10 2017 21:39:11 GMT+0530 (India Standard Time)",
  "__v": 0
}
{
  "errors": {
    "message": "Invalid long URL"
  }
}
{
  "errors": {
    "message": "Invalid base URL"
  }
}
{
  "errors": {
    "message": "Server error"
  }
}

POST /api/custom

Request schema

{
    "longUrl": "<the-long-url-to-be-shortened>",
    "urlCode": "<custom-code>"
}

Response schema

{
  "_id": "5f81dca70f685f2f104",
  "longUrl": "<the-long-url-to-be-shortened>",
  "shortUrl": "https://<base-url>/-i8bZ5O9B",
  "urlCode": "-i8bZ5O9B",
  "date": "Sat Oct 10 2017 21:39:11 GMT+0530 (India Standard Time)",
  "__v": 0
}
{
  "errors": {
    "message": "Code already in use"
  }
}
{
  "errors": {
    "message": "Invalid long URL"
  }
}
{
  "errors": {
    "message": "Invalid base URL"
  }
}
{
  "errors": {
    "message": "Server error"
  }
}

Instructions

  • Clone the repository
  • Install node from official website
  • Install the dependencies for the project using below command
    npm install
  • To run the application locally
    npm run dev
  • In the browser goto : http://localhost:5000/health

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Check Contributing.md for more instructions.

License

MIT

Releases

No releases published

Packages

No packages published