/blog-api

Primary LanguageGoApache License 2.0Apache-2.0

BinaryBlog

Go Version License Last Commit Issues Stars


BinaryBlog

Description

BinaryBlog is a blog backend api that allows users to create an account, verify their email address, login, create, update, delete blog posts, and search for blog posts.

Requirements

  • Go 1.21.5 and above
  • Postgres 13.3 and above
  • Docker 20.10.7 and above
  • sqlc 1.25.0 and above
  • golang-migrate 4.17.0 and above

Sqlc

# Docker recommended
docker run --rm -v $(pwd):/src -w /src sqlc/sqlc generate

or

Visit sqlc to install sqlc

Usage

go run cmd/api/blog/main.go [option]
# [option] = 1, 2

# 1: Database migration-up
# 2: Database migration-down

Keep in mind that you need to have a postgres database running on your local machine or in a docker container before running the above command

leave [option] empty to run the server

Endpoints

  • GET /api/v1/health

Users

POST /api/v1/user/signup This endpoint allows you to create a new user.
GET /api/v1/user/verify?token={token} This endpoint allows you to verify a user's email address.
POST /api/v1/user/login This endpoint allows you to login a user.
GET /api/v1/user/{id} This endpoint returns a specific user based on the provided ID.
DELETE /api/v1/user/{id} This endpoint allows you to delete a specific user based on the provided ID.
GET /api/v1/user/profile This endpoint returns the currently logged in user.
PUT /api/v1/user/profile This endpoint allows you to update the currently logged in user.

Posts

GET /api/v1/posts?page={page} This endpoint returns a list of posts with a limit of 10 posts per page. The page query parameter is optional and defaults to 1.
POST /api/v1/posts This endpoint allows you to create a new blog post.
GET /api/v1/posts/{id} This endpoint returns a specific blog post based on the provided ID.
PUT /api/v1/posts/{id} This endpoint allows you to update a specific blog post based on the provided ID.
DELETE /api/v1/posts/{id} This endpoint allows you to delete a specific blog post based on the provided ID.
GET /api/v1/article/search?match-type=single&term=python This endpoint allows you to search for a blog post based on the provided query parameters where match-type can be single or multi and term is the search term. The default match-type is single.