---
# System prepended metadata

title: API

---

Design a database schema and REST API for an application that allows users to post and read blogs.

* user can register
* user can find other users by name
* user can follow other users
* user can post a blog
* user can see a list of blogs posted by himself
* user can view the blog
* user can see a list of blogs posted by users he follows

# API

## Registration

## /auth/login
GET - return login state
POST - login

## /auth/logout
POST - logout

## /auth/register
POST - create account

## /users/{username}
GET - your profile or someone elses
PATCH - update profile
DELETE - delete profile

## GET /users/search/?name=jake

Blog post for users

## /users/{username}/blogs

## /blogs

## /{username}/{blogid}

# Database
Relational DB: Postgres/MySQL
# table: User
Columns:
- id (PKEY, sequential)
- email (varchar(255))
- name (varchar(255))
- password_hash (varchar(64))
- salt (varchar(64))

Index:
- email
- name

# table: Blog
Columns:
- id (PKEY, sequential)
- title (varchar(255))
- content (BLOB)
- user_id (FK)

Index:
- title
- fulltext content
- user_id

# table: Follows
Columns:
- id (PKEY, int64 sequential)
- user_id (int64)
- follower_id (int64)

Index:
- user_id
- user_id+follower_id