A RESTful API for a social media platform inspired by Twitter, built with Go and PostgreSQL.
- Getting Started
- API Endpoints
- Database Schema
- Environment Variables
- Security
- Testing
- Deployment
- Authors
- Go 1.17+
- PostgreSQL 13+
- Stripe account (for payment processing)
- Clone the repository:
git clone https://github.com/Fepozopo/chirpy.git - Install Go:
go install - Install PostgreSQL:
brew install postgresql(on macOS) - Create a PostgreSQL database:
createdb chirpy - Initialize the database schema:
goose postgres 'DB_URL' up - Set environment variables (see below)
- Run the API:
go run .
DB_URL: the PostgreSQL connection string (e.g.postgres://user:password@localhost/chirpy?sslmode=disable)TOKEN_SECRET: a secret key for generating JSON Web Tokens (e.g.my_secret_key)STRIPE_KEY: your Stripe API key (e.g.sk_test_...)
POST /api/users: create a new userGET /api/users/{id}: retrieve a user by IDPUT /api/users/{id}: update a userDELETE /api/users/{id}: delete a user
POST /api/chirps: create a new chirpGET /api/chirps: retrieve all chirpsGET /api/chirps/{id}: retrieve a chirp by IDDELETE /api/chirps/{id}: delete a chirp
POST /api/login: authenticate a user and generate a JSON Web TokenPOST /api/refresh: refresh a JSON Web TokenPOST /api/revoke: revoke a JSON Web Token
POST /api/polka/webhooks: handle Stripe webhooks (e.g. user.upgraded)
The database schema is defined in sql/schema. It consists of the following tables:
users: stores user information (e.g. email, hashed password)chirps: stores chirp information (e.g. body, user ID)refresh_tokens: stores refresh tokens (e.g. token, user ID, expiration date)
The API uses JSON Web Tokens for authentication and authorization. The TOKEN_SECRET environment variable is used to generate and verify tokens.
The API includes unit tests and integration tests. To run the tests, execute go test ./....