url-shortner

command module
v0.0.0-...-d12243e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

README ΒΆ

URL Shortener

Description

This is a simple URL shortener API implemented in Go. It allows users to submit any URL to be shortened and receive a valid shortened URL.

API Endpoints

Shorten a URL
  • Endpoint: /shortcode
  • Method: PUT
  • Request Body:
    {
      "destination": "valid url"
    }
    
    
    

URL Shortener


πŸ“ Table of Contents

🧐 About

The URL Shortener is a program which takes a Long URL in input and provides a Short URL in output. This Program uses Redis to Store Data Permanently. The Documentation of APIs will be found at API Documentation

🏁 Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See Deployment for notes on how to deploy the project on a Local System or on a Kubernetes Server.

Prerequisites

To run the URL Shortener on Local System, first we need to install following Software Dependencies.

Once above Dependencies are installed we can move with further steps

Installing

A step by step series of examples that tell you how to get a development env running.

Step 1: Setting Up Environmental Variables

Set up the Environmental variables according to your needs. The Application will run with defaults as mentioned in the following table

Environmental Variable Usage
REDIS_HOST Host where Redis is Running
REDIS_PORT Port where Redis is Running
Step 2: Run the Code
go build
./url-shortner

πŸ”§ Running the tests

To Run the Test Cases, Open a terminal in the Project and run following command

go test ./...

πŸ“ƒ API Documentation

Here are the API Endpoint used in this Project

ENDPOINT: /
REQUEST TYPE: GET
RESPONSES:
  Welcome to the URL Shortener!
ENDPOINT: /shortcode
REQUEST TYPE: PUT
BODY: 
RESPONSES:
  200: 
    {
      "short_url": "http://localhost/r/100680ad"
    }

  400:
    {
      "message": "Invalid JSON Format"
    }
  OR
    {
      "message": "Missing 'destination' field"
    }
  OR
    {
      "message": "Invalid URL"
    }

  500:
    {
      "message": "Internal Server Error : "
    }
ENDPOINT: r/{short_url}
REQUEST TYPE: GET
PATH PARAMETERS: short_url
RESPONSES:
  200: 
    Redirect to the Long URL
  
  404:
    {
      "message": "URL not found for localhost:5000/tstng"
    }

To check & Test the Supported Endpoints, and it's documentation, Run the Project and kindly use any of the methods mentioned below

πŸš€ Deployment

In order to deploy the Project on a Kubernetes Server kindly follow below steps:

kubectl create -f ./deployment/redis-service.yaml
kubectl create -f ./deployment/redis-deployment.yaml
kubectl create -f ./deployment/url-shortner-deployment.yaml
kubectl create -f ./deployment/url-shortner-service.yaml

API Host will be exposed on the URL Provided by URL Shortner Service

⛏️ Built Using

✍️ Authors

Documentation ΒΆ

The Go Gopher

There is no documentation for this package.

Directories ΒΆ

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL