Categorygithub.com/benskia/Chirpy
module
0.0.0-20240718190521-54550cbd7678
Repository: https://github.com/benskia/chirpy.git
Documentation: pkg.go.dev

# 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 NameData Type
emailString
passwordString

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 NameData Type
emailString
passwordString

Response:

{
    id: 0
    password: "password"
}
Field NameData Type
idInteger
passwordString

Login User

POST /api/login

Headers:

{
    Authorization: Bearer <token>
}

Request:

{
    email: "[email protected]"
    password: "password"
}
Field NameData Type
emailString
passwordString

Response:

{
    id: 0
    email: "[email protected]"
    token: "token"
    refresh_token: "refreshToken"
    is_chirpy_red: false
}
Field NameData Type
idInteger
emailString
tokenString
refresh_tokenString
is_chirpy_redBoolean

Refresh Token

POST /api/refresh

Headers:

{
    Authorization: Bearer <token>
}

Request:

{
    refresh_token: "refreshToken"
}
Field NameData Type
refresh_tokenString

Response:

{
    token: "token"
}
Field NameData Type
tokenString

Revoke Refresh Token

POST /api/revoke

Headers:

{
    Authorization: Bearer <token>
}

Request:

{
    refresh_token: "refreshToken"
}
Field NameData Type
refresh_tokenString

Response:

{
    token: "token"
}
Field NameData Type
tokenString

Upgrade User

POST /api/polka/webhooks

Headers:

{
    Authorization: ApiKey <polkaApiKey>
}

Request:

{
    event: "user.upgraded"
    data: {
        user_id: 0
    }
}
Field NameData Type
eventString
dataData

Data (Type)

Field NameData Type
user_idInteger

Get Chirps

GET /api/chirps/

GET /api/chirps/{authorID}

Response:

{
    chirps: [
        {
            id: 0
            body: "The body of a chirp."
            author_id: 0
        },
    ]
}
Field NameData Type
chirps[]Chirp

Chirp (Type)

Field NameData Type
idInteger
bodyString
author_idInteger

Post Chirp

POST /api/chirps

Headers:

{
    Authorization: Bearer <token>
}

Request:

{
    body: "The body of a new chirp."
}
Field NameData Type
bodyString

Response:

{
    {
        id: 0
        body: "The body of a chirp."
        author_id: 0
    }
}
Field NameData Type
idInteger
bodyString
author_idInteger

Delete Chirp

DELETE /api/chirps/{chirpID}

Headers:

{
    Authorization: Bearer <token>
}

# Packages

No description provided by the author