Skip to content

Latest commit

 

History

History
46 lines (37 loc) · 2.32 KB

README.md

File metadata and controls

46 lines (37 loc) · 2.32 KB

URL Shortener: A Go implementation of a URL shortener HTTP service

This URL shortener HTTP service shows short, easy to type URLs to end users.

What it does?

  • Provides an HTTP API to:
    • Shorten a URL
    • Redirect to the long URL from the shortened URL

Shortened URL characteristics:

Setup and how to run

After cloning the repository, run the project by executing the following command in the same directory as the docker-compose.yml file, making sure to pass in the redis database password as an environment variable:

sudo REDIS_DATABASE_PASSWORD=changetheworld docker compose up

Alternatively, you can run the project with go run . in the cmd/httpapi/server directory or install it by running go install in that same directory and then use:

url-shortner-poc

**Note that to run the project with docker compose you must install docker and docker compose. Other wise, if you're going to run the project on your local machine you must have a redis-server running in the background and set appendonly yes in the redis.conf file. See instructions for installing redis. On Linux you can find the redis.conf file in /etc/redis/redis.conf and on mac /usr/local/etc/redis.conf.

Routes

localhost:8080/shorten:

POST a JSON object like the one below, and receive the short URL in the response:

{
    "LongURL": "https://en.wikipedia.org/wiki/Main_Page/123456"
}

Result:

{
    "OriginalURL": "https://en.wikipedia.org/wiki/Main_Page/123456",
    "ShortURL": "https://localhost/04ec8683"
}

localhost:8080/{YOUR-SHORTENED-URL}

Send a GET request and you will be redirected to your long URL