Chirpy is a webserver that provides an API for a social media platform. It allows users to create chirps (short messages), retrieve chirps, delete chirps, and perform various user-related operations. The webserver is built using the Go programming language and the Chi router.
To run the Chirpy webserver, follow these steps:
- Clone the repository:
git clone https://github.com/tcluri/chirpy.git
- Install the dependencies:
go mod download
- Create a
.env
file in the root directory and set the required environment variables (e.g.,JWT_SECRET
andPOLKA_KEY
). - Build the application:
go build
- Run the webserver:
./chirpy
The Chirpy webserver provides the following API endpoints:
-
GET /api/healthz
: Health check endpoint to verify the server’s availability. -
POST /api/chirps
: Create a new chirp. -
GET /api/chirps
: Retrieve all chirps. -
GET /api/chirps/{chirpID}
: Retrieve a specific chirp by ID. -
DELETE /api/chirps/{chirpID}
: Delete a specific chirp by ID. -
PUT /api/users
: Update a user’s information. -
POST /api/users
: Create a new user. -
POST /api/login
: User login. -
POST /api/refresh
: Refresh an authentication token. -
POST /api/revoke
: Revoke an authentication token. -
POST /api/polka/webhooks
: Handle Polka webhooks for user upgrades(). -
GET /metrics
: Retrieve server metrics.
For examples, see request examples.
The Chirpy webserver supports the following configuration options:
JWT_SECRET
: Secret key for JWT token generation and validation.POLKA_KEY
: Secret key for handling Polka webhooks.
To run the webserver in debug mode, use the -debug
flag: ./chirpy -debug
. This will reset the database and enable debug logging.
The Chirpy webserver uses the following external dependencies:
github.com/go-chi/chi/v5
: Lightweight and expressive HTTP router for Go.github.com/joho/godotenv
: Go library for loading environment variables from a.env
file.