Skip to content

maliByatzes/url-shortener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ¦‹ url-shortener

A simple URL Shortener Service implemented with Redis caching.

πŸ¦‡ Features

  • ⭐ User can submit a long url and recieve a shortened url.
  • ⭐ User can share that short url which can be used anywhere to access the original url without having to remember the whole url.
  • ⭐ Caching is implemented for already accessed for very fast access times.

🐎 Tech Stack

  • ⭐ Bun.sh: A fast all-in-one JavaScript runtime.
  • ⭐ Hono.dev: Ultrafast web framework for the Edges.
  • ⭐ Typescript: JavaScript with syntax for types.
  • ⭐ MongoDB: Document-oriented database for storing data.
  • ⭐ Redis: World’s fastest in-memory database.

🐺 Application

πŸ¦… Run the application locally

🐝 Prerequisites

πŸ»β€β„οΈ Instatllation

  1. Clone the repository

    git clone https://github.com/maliByatzes/url-shortener
    cd url-shortener
  2. Install the dependencies

    bun install

🐸 Configuration

  1. Create an .env file in the project's root directory.

  2. Add the base url in the .env file:

    BASE=http://localhost:3000
  3. Get the MongoDB url from their site or you can set up a local mongodb connection, either way works:

    MONGODB_URI=...
  4. Set up a online or local redis database and add its connection url:

    REDIS_URL=...

πŸ— Usage

  1. Run the server:
    bun start

API Endpoints

  • POST: /short - post a long url to get a shorter one.

    curl --request POST \
    --url localhost:3000/short \
    --header 'Content-Type: application/json' \
    --data '{
      "origUrl": "some long valid url here"
     }'
  • Visit the returned short url on your browser to get redirected to the long url.

πŸ¦• Deployed Application

  • To avoid the tedious setup, the application is already deployed. Use the below POST command to requst a shortned URL. But of course the service I used gave a not so short base URL but the service works as expected.

  • POST: /short - post a long url to get a shorter one.

    curl --request POST \
    --url https://short-url-v0sc.onrender.com/short \
    --header 'Content-Type: application/json' \
    --data '{
      "origUrl": "some long valid url here"
     }'
  • Visit the returned short url on your browser to get redirected to the long url.

🦝 License

This project is licensed under MIT License.

🦦 Contact