Skip to content

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chirpy

Chirpy is a simple blog engine written in Go:

  • It allows storing users and their posts using a REST API.
  • Builded using standard library
  • Posts and users are stored in a PostgreSQL database.
  • Passwords are hashed using bcrypt.
  • Authorization is done using JSON Web Tokens, that are refreshed every hour.
  • Handle 'Polka' Webhook with authorization.

API

Users

POST /api/users

Creates a new user.

Parameters:

{
  "email": "email@example.com",
  "password": "password"
}

Returns 201 if successful:

{
  "id": "123e4567-e89b-12d3-a456-426655440000",
  "createdAt": "2021-01-01T00:00:00Z",
  "updatedAt": "2021-01-01T00:00:00Z",
  "email": "email@example.com"
}

PUT /api/users

Updates a user.

Parameters:

Headers: Authorization: Bearer {token}

{
  "email": "email@example.com",
  "password": "password"
}

Returns 200 if successful:

{
  "id": "123e4567-e89b-12d3-a456-426655440000",
  "createdAt": "2021-01-01T00:00:00Z",
  "updatedAt": "2021-01-01T00:00:00Z",
  "email": "email@example.com",
  "token": "JWT.Token.Structure",
  "refresh_token": "generated_string",
  "is_chirpy_red": true
}

POST /api/login

Logs in a user.

Parameters:

{
  "email": "email@example.com",
  "password": "password"
}

Returns 200 if successful:

{
  "id": "123e4567-e89b-12d3-a456-426655440000",
  "createdAt": "2021-01-01T00:00:00Z",
  "updatedAt": "2021-01-01T00:00:00Z",
  "email": "email@example.com",
  "token": "JWT.Token.Structure",
  "refresh_token": "generated_string"
}

Posts (Chirps)

GET /api/chirps?author_id={id}?sort=asc|desc

Returns a list of posts:

  • All if author_id is not set.
  • By author if author_id is set.
  • Sorted by creation date in sort order (asc by default).
[
  {
    "id": "123e4567-e89b-12d3-a456-426655440000",
    "createdAt": "2021-01-01T00:00:00Z",
    "updatedAt": "2021-01-01T00:00:00Z",
    "body": "Hello, world!",
    "user_id": "123e4567-e89b-12d3-a456-426655440000"
  }
]

GET /api/chirps/{id}

Returns a post for current user.

{
  "id": "123e4567-e89b-12d3-a456-426655440000",
  "createdAt": "2021-01-01T00:00:00Z",
  "updatedAt": "2021-01-01T00:00:00Z",
  "body": "Hello, world!",
  "user_id": "123e4567-e89b-12d3-a456-426655440000"
}

POST /api/chirps

Creates a new post for current user.

Headers: Authorization: Bearer {token}

Parameters:

{
  "body": "Hello, world!"
}

Returns 201 if successful:

{
  "id": "123e4567-e89b-12d3-a456-426655440000",
  "createdAt": "2021-01-01T00:00:00Z",
  "updatedAt": "2021-01-01T00:00:00Z",
  "body": "Hello, world!",
  "user_id": "123e4567-e89b-12d3-a456-426655440000"
}

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages