Shortify is a URL shortening service written in Golang. It provides two endpoints, POST and GET, for creating and retrieving shortened URLs, respectively. The original URL is base62 decoded and shortened with the application's domain, which is valid for 24 hours. The original URL, shortened URL, creation time, and expiry time are stored in both MySQL database and Redis. The POST endpoint checks if the URL already exists in Redis, and if not, it generates and saves it. The GET endpoint checks if the URL exists in Redis, and if not, it retrieves it from the database and does a 301 redirect to the original URL.
To run Shortify, you need to have Docker and Docker Compose installed on your system.
-
Clone the repository to your local machine.
git clone https://github.com/<your-username>/shortify.git
-
Navigate to the project directory.
cd shortify
-
Build the Docker image.
docker build -t shortify .
-
Run the Docker containers using Docker Compose.
docker-compose up -d
Shortify should now be up and running at http://localhost:8081
.
The POST endpoint is used to create a shortened URL.
URL: /
Method: POST
Headers:
Content-Type: application/json
Body:
{ "original_url": "https://example.com/very-long-url-that-needs-to-be-shortened" }
Response:
{ "data": { "url": "localhost:8081/013" }, "error": null }
The GET endpoint is used to retrieve the original URL from a shortened URL.
URL: data.url
from previous POST
request
Method: GET
Response: A 301 redirect to the original URL.
A Postman collection is included in the repository (shortify.postman_collection.json
) that contains sample requests for the POST endpoint.