A Rust web application that provides URL shortening service with Google OAuth authentication.
- URL shortening with custom short codes
- Google OAuth authentication
- Visit tracking for shortened URLs
- PostgreSQL database backend
- Rust (latest stable version)
- PostgreSQL
- Google OAuth credentials
- Clone the repository
- Create a PostgreSQL database
- Copy
.env.exampleto.envand 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 - Set up your Google OAuth credentials at the Google Cloud Console
- Run database migrations:
psql -U your_username -d url_shortener -f migrations/20240404_init.sql
- Build and run the project:
cargo run
GET /auth/google/login- Initiate Google OAuth loginGET /auth/google/callback- Google OAuth callbackPOST /api/shorten- Create short URL{ "url": "https://example.com/very/long/url" }GET /s/{short_code}- Redirect to original URL
- Visit
http://localhost:8080/auth/google/loginto log in with Google - 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"}' - Share and use your shortened URLs!