Tried to replicate twitter backend in 2 days.
- Written in GoLang
- Uses Relational DB - Postgres (Pardon to not to use GraphQL)
- Uses JWT over web sessions
- Uses Redis to create blacklist (expired JWT Tokens) for session maintainence
Note: Just for reference. Go builds everything from vendor.
- https://github.com/go-chi/chi
- https://github.com/dgrijalva/jwt-go
- https://github.com/go-redis/redis
- https://github.com/lib/pq
- https://github.com/jmoiron/sqlx/reflectx
- https://golang.org/x/crypto/bcrypt
- Install Go and set up ENVIRONMENT (https://golang.org/doc/install)
- Clone repository to $HOME/go/src/
- Run -> go get -u github.com/kardianos/govendor
- Install Postgres
- Create a database named, 'postman-twitter'
- Open /database/init_db.go and set username and database value.
"user=yashishdua dbname=postman-twitter sslmode=disable"
- Run
db
bash script present in the project root to execute psql db schema on local
sh db
- Install Redis: brew install redis
- Start Redis Server: redis-server /usr/local/etc/redis.conf
- Default port: 6379
- Run 'run' bash script present in the project root to build and run server
sh run
- Current port: 8000
- Change port configuration in /config/config_local.json
Endpoint:
/api/v1/auth/signup
Method: POST
Body:
{
"username": "yashishdua",
"password": "test"
}
Endpoint:
/api/v1/auth/signin
Method: POST
Body:
{
"username": "yashishdua",
"password": "test"
}
Successful Response:
{
"jwt_token": "eyJhbGciOiJIUzI1NiIsInR5c....",
"user_id": "8559ab00-8a02-487e-8b82-3adbf4fbe69e"
}
Endpoint:
/api/v1/auth/signout
Method: POST
Header:
Key: Authorization
Value: Bearer <jwt_token>
ASSUMPTION: You are providing valid user id
Endpoint:
/api/v1/user/{userID}/follow
Method: POST
Header:
Key: Authorization
Value: Bearer <jwt_token>
Body:
{
"followed_by_user_id": "8559ab00-8a02-487e-8b82-3adbf4fbe99e"
}
ASSUMPTION: You are providing valid user id
Endpoint:
/api/v1/user/{userID}/unfollow
Method: POST
Header:
Key: Authorization
Value: Bearer <jwt_token>
Body:
{
"followed_by_user_id": "8559ab00-8a02-487e-8b82-3adbf4fbe99e"
}
Singing off.