Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Interview Challenge: URL Shortener (Django + DRF)

Timed exercise for building a small app with AI assistance allowed.

Rules

  • You may use AI tools freely (Cursor, ChatGPT, Copilot, etc.).
  • You must be able to explain every line you keep.
  • Prefer a small working slice over unfinished extras.
  • Time box: ~60 minutes for a working happy path.

Goal

Build a URL shortener API with Django and Django REST Framework.

Required

  1. POST /api/shorten/ — accept a long URL, return a short code / short URL
  2. GET /<code>/ — redirect to the original URL
  3. Persist links across process restart (SQLite is already configured)
  4. Reject non-http / non-https URLs (including javascript:, empty, nonsense)

Nice to have (only after required works)

  • Basic test(s) for create + redirect + invalid URL
  • Unknown short code returns 404
  • Simple click counter or expiry

Out of scope

  • Auth, custom domains, analytics dashboards, Redis, Docker, deployment

Setup

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python manage.py migrate
python manage.py runserver

Starter layout

config/          # Django project settings / urls
shortener/       # Your app — implement models, serializers, views, urls

Stub endpoints are wired but intentionally unfinished. Fill them in.

Suggested demo script (end of interview)

# create
curl -s -X POST http://127.0.0.1:8000/api/shorten/ \
  -H 'Content-Type: application/json' \
  -d '{"url":"https://example.com"}'

# visit the returned short URL in a browser (or curl -i) and confirm redirect

# reject bad schemes
curl -s -X POST http://127.0.0.1:8000/api/shorten/ \
  -H 'Content-Type: application/json' \
  -d '{"url":"javascript:alert(1)"}'

# restart the server, then confirm the short link still works

Deliverable

  • Runnable app
  • Short note in this README (or a NOTES.md) with:
    • how to run
    • how you tested
    • one known limitation

About

Timed Django + DRF interview challenge: build a URL shortener with AI assistance allowed.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages