A simple social media API built with Go that allows users to post short messages called "chirps". The stored data is persisted in a PostgreSQL database.
- User authentication with JWT
- Create, read, and delete chirps
- User registration and login
- Sort chirps by creation date
- Filter chirps by author
- Chirpy Red premium user status
POST /api/users
- Register a new user- Body:
{ "email": "[email protected]", "password": "password123" }
- Body:
POST /api/login
- Login and receive JWT token- Body:
{ "email": "[email protected]", "password": "password123" }
- Body:
PUT /api/users
- Update user details- Body:
{ "email": "[email protected]", "password": "newpassword123" }
- Body:
POST /api/chirps
- Create a new chirp- Body:
{ "body": "Hello, world!" }
- Body:
GET /api/chirps
- Get all chirps- Query params:
author_id
- Filter by authorsort
- Sort order ("asc" or "desc")
- Query params:
GET /api/chirps/{chirpID}
- Get a specific chirpDELETE /api/chirps/{chirpID}
- Delete a chirp (auth required)
POST /api/polka/webhook
- Handle Polka webhook
- Clone the repository
- Create a
.env
file with:PLATFORM=dev POLKA_KEY=your_polka_key JWT_SECRET=your_jwt_secret (Got from openssl rand -base64 64) DB_URL=postgresql://user:password@localhost:5432/dbname
- Install dependencies:
go mod download
- Run database migrations:
goose postgres "your_db_connection_string" up
- Start the server:
go run main.go
Most endpoints require JWT authentication. Include the token in requests:
{
"Authorization": "Bearer <token>"
}