short-url

command module
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2023 License: MIT Imports: 4 Imported by: 0

README

Short URL

A fully functional URL shortener using MySQL as the storage server and Redis as the cache server.

The current components include:

  • A web server for URL shortening and redirection
  • [TODO] logging
  • [TODO] connection pooling
  • [TODO] Redis cache server
  • [TODO] a rate limiter middleware
  • [TODO] logging

Usages

We provide two API endpoints: one for URL shortening and another for URL redirection.

URL shortening

POST /api/v1/data/shorten

  • Request parameter: {longURL: string}
  • Rreturn: shortURL

Example usage:

$ curl -iX POST 'http://localhost:8080/api/v1/data/shorten?longURL=www.google.com'
URL redirection

GET /api/v1/:shortURL

  • Return: longURL for HTTP redirection

Example usage:

shortURL: The URL you get from the previous step, or any short URL in the database

$ curl -i 'http://localhost:8080/api/v1/shortURL'

Command Runner

We use the command runner just as an alternative to makefile. Execute just help to access a complete list of available commands.

Build and Run Locally

We use docker-compose to set up local development pretty easily. It exposes a web server forwarded to host port 8080, a MySQL server forwarded to host port 3306, and a Redis server forwarded to host port 6379. To launch, simply run:

$ docker-compose up -d

Then you are ready to go.

To connect to the mysql server, run:

$ just mysql

To connect to the redis server, run:

$ just mysql

License

MIT License

Documentation

Overview

Copyright © 2023 Zecheng Qian

Directories

Path Synopsis
internal
db

Jump to

Keyboard shortcuts

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