Chirpy is aTwitter-esque API that allows for users to create chirps. This project was built as part of a boot.dev course.
- Go version <= 1.23.x
- Postgres running locally or in a container.
- goose for migrations.
- Clone this repository
- Create a
.envfile in the project root directory.- Should have the following keys:
DB_URLpostgres database urlENVIRONMENTshould bedevSECRET_KEYkey used to hash and verify passwords.POLKA_KEYapi key for a fake payment processing service.
- Should have the following keys:
- Create a new table in your postgres db called
chirpyand set the owner role according to your db url. - Navigate to
sql/schemaand run `goose postgres "<your db url<" up
go build && ./chirpyorgo run .to start the server.
To run the tests, navigate to the root of the project and run go test ./...
Chirpy uses JWT authentication with a refresh token. If an endpoint is marked as (auth
required), that means you will need to send a header with the following format:
Authorization: Bearer <jwt>. In addition, users can only edit chirps that they
created and can only update themselves and not other users.
GET: Check server health.
GET: Return how many times the/apppath was accessed.
POST: Drop all rows from all tables in the DB.
POST: Create a new user.- Request body:
{"email": "example@email.com", "password": "password"}- Response body:
{ "id": <uuid>, "email": <string>, "created_at": <timestamp>, "updated_at": <timestamp>, "is_chirpy_red": <bool> }PUT(auth required): Same asPOST
POST(auth required): Create a chirp.- Request body:
{ "body": <string>, }- Response body:
{ "id": <uuid>, "body": <string>, "created_at": <timestamp>, "updated_at": <timestamp>, "user_id": <uuid> }GET:- query parameters:
sort:ascordescbycreated_atauthor_id: author id
- Response body:
[ <chirp(same as post response)>, ... ]- query parameters:
GET: Get a single chirp- Response body: Same as
/api/chirpspost response.
- Response body: Same as
DELETE(auth required): Delete a chirp
POST: Log in and get a JWT and refresh token.- Request body:
{ "email": <string>, "password": <string> }- Response body:
{ "id": <uuid>, "email": <string>, "created_at": <timestamp>, "updated_at": <timestamp>, "is_chirpy_red": <bool>, "token": <string>, "refresh_token": <string> }
POST: Revoke a refresh token. Refresh token must be provided in auth header.
POST: Refresh a JWT. Requires refresh token in auth header.