Giter Club home page Giter Club logo

go-url-shortener's Introduction

URL shortening service

A simple project developing a URL shortening service, primarily backend, using Golang.

Motivation

To built a backend service using Go and it's frameworks, and to try out creating an containerised application off of that service to gain hands-on experience.

Architecture

Picture

Tech stack used

  • Go
  • Redis (for database)
  • Fiber (for web services)
  • Docker (for containerisation)

Requirements

Local setup

  1. Clone the repository.
git clone https://github.com/PMohanJ/go-url-shortener.git
  1. Make sure you've all the Requirements/dependencies installed in your system.

  2. Enter project directory.

cd go-url-shortener
  1. Now initiate the docker-compose file to start the application.
docker-compose up

Usage

After the container is up and running, you can make requests to the application at following port http://localhost:3000/

  • Send a request with following syntax:
curl localhost:3000/api/v1 -H "Content-Type":"application/json" \
-d '{"url": "https://www.youtube.com/watch?v=R_fZjGm2OrM"}'

Response for above request looks as below

{
    "url":"https://www.youtube.com/watch?v=R_fZjGm2OrM",
    "short":"localhost:3000/dd2970",
    "expiry":24,
    "rate_limit":6,
    "rate_limit_reset":12
}
  • The application does even support custom url, for example:
curl localhost:3000/api/v1 -H "Content-Type":"application/json" \
-d '{"url": "https://www.youtube.com/watch?v=R_fZjGm2OrM", "short":"123@Mine"}'

Response to above command

{
    "url":"https://www.youtube.com/watch?v=R_fZjGm2OrM",
    "short":"localhost:3000/123@Mine",
    "expiry":24,
    "rate_limit":5,
    "rate_limit_reset":8
}
  • You can also set the custom expiry time for the URL, which actaully defaults to 24hr if not set:
curl localhost:3000/api/v1 -H "Content-Type":"application/json" \
 -d '{"url": "https://www.youtube.com/watch?v=R_fZjGm2OrM", "expiry":10}'

Response to above command

{
    "url":"https://www.youtube.com/watch?v=R_fZjGm2OrM",
    "short":"localhost:3000/325800",
    "expiry":10,
    "rate_limit":4,
    "rate_limit_reset":6
}

So, whenever you use the shortened URL, you'll will be redirected to original URL.

go-url-shortener's People

Contributors

pmohanj avatar

Watchers

 avatar

go-url-shortener's Issues

Error while creating service db

Description

An error is occurring while initiating the docker-compose file for stating of application.

Error is as follows:
Screenshot from 2022-11-02 11-36-17

May be something wrong with database docker file.

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.