Skip to content

sebsojeda/url-shortener

Repository files navigation

URL Shortener

A fast, tiny URL shortener API.

Development

  1. Install Bun dependencies:
bun install
  1. Start the MySQL database and Redis server:
docker compose up
  1. Run the database migrations:
bunx tsx src/migrate.ts
  1. Start the Bun server:
bun run src/server.ts

Usage

Shorten a URL

curl -X POST -H "Content-Type: application/json" -d '{"url": "https://example.com"}' http://localhost:8080
{
  "url": "https://example.com",
  "alias": "<url-alias>"
}

Redirect to a URL

curl -I http://localhost:8080/<url-alias>
HTTP/1.1 301 Moved Permanently
Location: https://example.com