A Hashnode inspired blog API to practice PostgreSQL and learn Prisma ORM.
All passwords are hashed with bcrypt.js before they are stored in the database. JWT tokens are used to login and protect user data.
Follow these steps to run a local instance of this API. (You will need node, npm, and PostgreSQL already installed.)
- Clone the project
git clone git@github.com:LamiSaadat/blog-api.git
-
Create a new database in pgadmin.
-
Install dependencies
npm install
- Run migrations
npm run migrate
- Set environment variables:
Rename .env_sample
to .env
and change the placeholder values.
DATABASE_URL=<postgresql://USER:PASSWORD@HOST:PORT/DATABASE>
ACCESS_TOKEN_SECRET=<your secret>
PORT=<a port number>
- Start the server
npm start
- Register a user
- Login a user
- View all published posts
- View all user profiles
- View all followers of a user
- Logged in users can
- Create posts
- Create draft posts only visible to creator
- Edit own posts
- Delete own posts
- Comment on posts
- Like, and then unlike posts
- Follow/Unfollow other users
Blog.API.mov
POST /user/signup
{
"firstName": "Rory",
"lastName": "Gilmore",
"email": "rory@gmail.com",
"password": "123"
}
POST /user/login
{
"email": "rory@gmail.com",
"password": "123"
}
POST /user/account
POST /user/:id/profile
POST /user/:id/follow
POST /user/:id/unfollow
POST /user/:id/followers
GET /posts/feed
POST /posts/create
{
"title": "test post title 4",
"content": "test post content",
"authorEmail": "givemecoffee@gmail.com",
"published": false
}
PATCH /posts/:id
{
"title": "edited title",
"content": "edited content",
"published": true
}
GET /posts/drafts
DELETE /posts/:id
POST /posts/:id/comment
{
"comment": "sample comment",
}
POST /posts/:id/like
{
"like": true
}
POST /posts/:id/unlike
- Good documentation saves a lot of time and tears
- Learned about implicit vs explicit many-to-many relations which helped with creating the like and follow systems which was a struggle
- Learned to apply auth with jwt
- Learned to use pgadmin
- Learned Prisma migrations, and editing tables and creating new migrations
Node, Express, PostgreSQL, Prisma