# README
Chirpy WebServer
A RESTful API that simulates creating and logging in users to post and manage short messages. JWT and refresh tokens are used to authenticate users, and the database (currently JSON) allows concurrent access with read/write mutexes.
Built with GO version 1.22.5
Installation
Download and install GO
https://go.dev/doc/install
Clone This Repository
git clone https://github.com/benskia/Chirpy.git
Manage Dependencies
From project root: go mod tidy
Build
From project root: go build -o ./bin/chirpy ./cmd/chirpy/main.go
Run
From project root: ./bin/chirpy
Use the API
By default, the server will be live at localhost:8080
. Depending on the
endpoint, either visit it in a web browser or send a request (such as with
curl, wget, etc).
Readiness
Responds with OK while the webserver is live.
GET /api/healthz
Metrics
Displays the number of requests sent to /api/* endpoints.
GET /admin/metrics
Resets the current request count.
GET /api/reset
Create User
POST /api/users
Request:
{
email: "[email protected]"
password: "password"
}
Field Name | Data Type |
---|---|
String | |
password | String |
Response:
{
id: 0
email: "[email protected]"
is_chirpy_red: false
}
Update User
PUT /api/users
Headers:
{
Authorization: Bearer <token>
}
Request:
{
email: "[email protected]"
password: "password"
}
Field Name | Data Type |
---|---|
String | |
password | String |
Response:
{
id: 0
password: "password"
}
Field Name | Data Type |
---|---|
id | Integer |
password | String |
Login User
POST /api/login
Headers:
{
Authorization: Bearer <token>
}
Request:
{
email: "[email protected]"
password: "password"
}
Field Name | Data Type |
---|---|
String | |
password | String |
Response:
{
id: 0
email: "[email protected]"
token: "token"
refresh_token: "refreshToken"
is_chirpy_red: false
}
Field Name | Data Type |
---|---|
id | Integer |
String | |
token | String |
refresh_token | String |
is_chirpy_red | Boolean |
Refresh Token
POST /api/refresh
Headers:
{
Authorization: Bearer <token>
}
Request:
{
refresh_token: "refreshToken"
}
Field Name | Data Type |
---|---|
refresh_token | String |
Response:
{
token: "token"
}
Field Name | Data Type |
---|---|
token | String |
Revoke Refresh Token
POST /api/revoke
Headers:
{
Authorization: Bearer <token>
}
Request:
{
refresh_token: "refreshToken"
}
Field Name | Data Type |
---|---|
refresh_token | String |
Response:
{
token: "token"
}
Field Name | Data Type |
---|---|
token | String |
Upgrade User
POST /api/polka/webhooks
Headers:
{
Authorization: ApiKey <polkaApiKey>
}
Request:
{
event: "user.upgraded"
data: {
user_id: 0
}
}
Field Name | Data Type |
---|---|
event | String |
data | Data |
Data (Type)
Field Name | Data Type |
---|---|
user_id | Integer |
Get Chirps
GET /api/chirps/
GET /api/chirps/{authorID}
Response:
{
chirps: [
{
id: 0
body: "The body of a chirp."
author_id: 0
},
]
}
Field Name | Data Type |
---|---|
chirps | []Chirp |
Chirp (Type)
Field Name | Data Type |
---|---|
id | Integer |
body | String |
author_id | Integer |
Post Chirp
POST /api/chirps
Headers:
{
Authorization: Bearer <token>
}
Request:
{
body: "The body of a new chirp."
}
Field Name | Data Type |
---|---|
body | String |
Response:
{
{
id: 0
body: "The body of a chirp."
author_id: 0
}
}
Field Name | Data Type |
---|---|
id | Integer |
body | String |
author_id | Integer |
Delete Chirp
DELETE /api/chirps/{chirpID}
Headers:
{
Authorization: Bearer <token>
}