Code Monkey home page Code Monkey logo

url-shortener's Introduction

URL Shortener

This is a simple URL shortener application that utilizes MD5 hashing to create short links for URLs. The application is designed following Domain-Driven Design (DDD) principles and uses Redis as a cache to enhance performance.

How it Works

The URL shortener provides two endpoints to handle shortening and retrieving original URLs:

  1. Shorten URL Endpoint

    • Endpoint: POST /short
    • Request Body: {"origin_link": "google.com"}
    • Response:
      {
        "shortened_link": "1c383cd30b7c298ab50293adfecb7b18",
        "expires_at": "2023-07-20T03:55:33.257126Z",
        "message": "OK!"
      }

    When a POST request is made to the /short endpoint with the origin_link, the application generates an MD5 hash for the URL, creating a shortened link. The response includes the shortened_link and an expires_at timestamp indicating the expiration date of the short link. Additionally, a "OK!" message is returned to indicate the successful creation of the short link.

  2. Retrieve Original URL Endpoint

    • Endpoint: POST /origin
    • Request Body: {"shortened_link": "1c383cd30b7c298ab50293adfecb7b18"}
    • Response:
      {
        "origin_link": "google.com",
        "expires_at": "2023-07-20T03:55:33Z",
        "message": "OK!"
      }

    When a POST request is made to the /origin endpoint with the shortened_link, the application looks up the original URL associated with the given shortened link and returns it. The response includes the origin_link and an expires_at timestamp indicating the expiration date of the original link. A "OK!" message is also included in the response.

Requirements

To run the URL shortener application, you need the following:

  • Golang
  • Docker Compose

Installation and Setup

  1. Clone the repository
  2. Setup Deployments

Before running the URL shortener, ensure that you have set up the necessary deployments, such as setting up the Redis server or any other configurations required for your specific environment using this command:

make developements
  1. Build Go Files

Use the following command to build the Go files for the URL shortener:

make url-shortener
  1. Migrate Database Run the migration to set up the database schema for the URL shortener:
./url-shortener migrate
  1. Run Server

Start the URL shortener server:

./url-shortener serve

Note

Feel free to contribute and improve the application. Happy URL shortening!

url-shortener's People

Contributors

asdafi avatar unknownasdfi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.