A simple URL Shortener Service implemented with Redis caching.
- β 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.
- β 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.
-
Clone the repository
git clone https://github.com/maliByatzes/url-shortener cd url-shortener
-
Install the dependencies
bun install
-
Create an .env file in the project's root directory.
-
Add the base url in the .env file:
BASE=http://localhost:3000
-
Get the MongoDB url from their site or you can set up a local mongodb connection, either way works:
MONGODB_URI=...
-
Set up a online or local redis database and add its connection url:
REDIS_URL=...
- Run the server:
bun start
-
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.
-
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.
This project is licensed under MIT License.