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.
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"
}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
}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"
}Returns a list of posts:
- All if
author_idis not set. - By author if
author_idis set. - Sorted by creation date in
sortorder (ascby 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"
}
]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"
}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"
}