A small Twitter-like HTTP API written in Go. Users can register, log in, post short messages ("chirps"), and read or filter chirps from other users. Built as a learning project working through the Boot.dev backend course.
- User registration and login with hashed passwords (argon2id)
- JWT access tokens + database-backed refresh tokens with revocation
- Authenticated chirp creation, deletion (only by the author), and update of own account
- Filtering chirps by author and sorting by date
- "Chirpy Red" premium membership upgraded via incoming Polka webhooks (API-key authenticated)
- Admin endpoints (metrics page, dev-only data reset) gated by
PLATFORM=dev
It's a complete backend in idiomatic Go's standard library - no web framework. Useful as a reference for:
- HTTP routing with Go 1.22+ method-prefixed
ServeMuxpatterns (e.g.GET /api/chirps/{chirpID}) - JWT issue / verify / refresh / revoke flows
- sqlc + goose for type-safe SQL and versioned migrations
- Webhook authentication via API keys
- Go (standard
net/http) - PostgreSQL with
lib/pq - goose for migrations, sqlc for query code generation
- golang-jwt/jwt v5 for JWTs, argon2id for password hashing
- Go 1.22+
- PostgreSQL running locally
goose—go install github.com/pressly/goose/v3/cmd/goose@latestsqlc(only needed if you change SQL files)
psql postgres -c "CREATE DATABASE chirpy;"Create a .env file in the project root:
DB_URL="postgres://postgres:postgres@localhost:5432/chirpy?sslmode=disable"
PLATFORM="dev"
JWT_SECRET="<output of: openssl rand -base64 64>"
POLKA_KEY="<your polka api key>"goose -dir sql/schema postgres "$DB_URL" upgo run .Server listens on :8080.
# Register
curl -X POST http://localhost:8080/api/users \
-H "Content-Type: application/json" \
-d '{"email":"you@example.com","password":"password123"}'
# Log in (returns access + refresh tokens)
curl -X POST http://localhost:8080/api/login \
-H "Content-Type: application/json" \
-d '{"email":"you@example.com","password":"password123"}'
# Post a chirp
curl -X POST http://localhost:8080/api/chirps \
-H "Authorization: Bearer <access_token>" \
-H "Content-Type: application/json" \
-d '{"body":"hello world"}'
# List all chirps
curl http://localhost:8080/api/chirps
# Filter and sort
curl "http://localhost:8080/api/chirps?author_id=<uuid>&sort=desc"