This is a microblogging platform designed with modern APIs, secure authentication, and extensibility. Users can post, delete, and manage "chirps" (short messages), as well as benefit from premium features such as "Chirpy Red" membership.
This project demonstrates a complete backend implementation using Go, PostgreSQL, and best practices for API development.
- User Management: Create, update, and authenticate users.
- Microblogging: Post, retrieve, and delete chirps.
- Premium Membership: Support for "Chirpy Red" with exclusive features.
- Webhooks: Integrate external services using secure API keys.
- Readiness & Metrics: Includes health checks and monitoring endpoints.
- Go: Version 1.19 or higher.
- PostgreSQL: Version 15. Ensure the database is running.
- Environment Configuration:
- Use
.env
to configure the application (see below for required values).
- Use
git clone https://github.com/1729prashant/microbloggingplatform.git
cd microbloggingplatform
- Login to PostgreSQL and create a new PostgreSQL database.
CREATE DATABASE chirpy;
- Ensure the connection URL is available (e.g.,
postgres://username:password@localhost:5432/chirpy
).
Create a .env
file in the project root with the following variables:
DB_URL=postgres://username:password@localhost:5432/chirpy
PLATFORM=dev
JWT_SECRET=<your_jwt_secret>
POLKA_KEY=<your_key_here>
go mod tidy
Use a migration tool such as migrate to initialize the database schema.
Example:
migrate -database $DB_URL -path migrations up
go run main.go
- Create User:
POST /api/users
- Update User:
PUT /api/users
- Login:
POST /api/login
- Refresh Token:
POST /api/refresh
- Revoke Token:
POST /api/revoke
- Get All Chirps:
GET /api/chirps?author_id=<uuid>&sort=<asc|desc>
- Create Chirp:
POST /api/chirps
- Get Chirp by ID:
GET /api/chirps/<chirpID>
- Delete Chirp:
DELETE /api/chirps/<chirpID>
- Metrics:
GET /admin/metrics
- Reset:
POST /admin/reset
(Development mode only)
- Polka Webhook:
POST /api/polka/webhooks
- Clean Code Practices: Follows Go conventions for error handling, middleware, and separation of concerns.
- Security:
- Uses JWT for authentication.
- Polka webhook requests require API key validation.
- Extensibility: Easily extendable for additional endpoints or business logic.
-
Cannot Connect to Database:
- Verify the
DB_URL
in the.env
file. - Ensure PostgreSQL is running on the correct port.
- Verify the
-
Missing API Key:
- Confirm
POLKA_KEY
is set correctly in the.env
file.
- Confirm
-
JWT Issues:
- Ensure
JWT_SECRET
is set in the.env
file.
- Ensure
Project likely to undergo significant changes. Chirps might become blogposts or something more generic. The end purpose is to have a code base that is multipurpose and can be customised for you.