/url-shortener

URL Shortener API

Primary LanguageGo

ci

URL Shortener written in Golang

Prerequisites

  • Golang
  • Docker
  • Docker Hub Account

Steps to run the unit tests

make test

Steps to run the server locally

make run

Steps to run the server in Docker container

  • Run the following command to build the Docker image:

    make docker-build
  • Run the following command to start the Docker container:

    make docker-run

Steps to call the API's

URL Shortening API

Request

curl --location 'localhost:3000' \
--header 'Content-Type: application/json' \
--data '{
    "longURL": "https://github.com/sagar-jadhav"
}'

Response

You should get the response in the below format. Data might vary as the short URL is generated randomly. But once you generated the Short URL you will get the same response till the application is running.

{
    "longURL": "https://github.com/sagar-jadhav",
    "shortURL": "http://localhost:3000/qIFxf"
}

Metrics API

Request

curl --location 'http://localhost:3000/metrics'

Response

[
    {
        "domain": "github.com",
        "count": 1
    }
]

Note:

I have already pushed the image to DockerHub So If you want to run the application without building it then run the following command:

docker run -d -p 3000:3000  --name url-shortener developersthought/url-shortener:1.0