Skip to content

ky-shinsoft/short-url-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

URL Shortener with Google OAuth

A Rust web application that provides URL shortening service with Google OAuth authentication.

Features

  • URL shortening with custom short codes
  • Google OAuth authentication
  • Visit tracking for shortened URLs
  • PostgreSQL database backend

Prerequisites

  • Rust (latest stable version)
  • PostgreSQL
  • Google OAuth credentials

Setup

  1. Clone the repository
  2. Create a PostgreSQL database
  3. Copy .env.example to .env and fill in your configuration:
    DATABASE_URL=postgresql://username:password@localhost:5432/url_shortener
    GOOGLE_CLIENT_ID=your_google_client_id
    GOOGLE_CLIENT_SECRET=your_google_client_secret
    REDIRECT_URL=http://localhost:8080/auth/google/callback
    APP_HOST=127.0.0.1
    APP_PORT=8080
    
  4. Set up your Google OAuth credentials at the Google Cloud Console
  5. Run database migrations:
    psql -U your_username -d url_shortener -f migrations/20240404_init.sql
  6. Build and run the project:
    cargo run

API Endpoints

  • GET /auth/google/login - Initiate Google OAuth login
  • GET /auth/google/callback - Google OAuth callback
  • POST /api/shorten - Create short URL
    {
      "url": "https://example.com/very/long/url"
    }
  • GET /s/{short_code} - Redirect to original URL

Usage

  1. Visit http://localhost:8080/auth/google/login to log in with Google
  2. Use the API to create short URLs:
    curl -X POST http://localhost:8080/api/shorten \
         -H "Content-Type: application/json" \
         -d '{"url":"https://example.com/very/long/url"}'
  3. Share and use your shortened URLs!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages