What You’ll Build
By the end of this tutorial you’ll have a working blog API with:- Users who can write posts
- Posts that belong to users and have many comments
- Comments that belong to both a post and a user
- Pagination, filtering, and soft deletes
This tutorial assumes you’ve completed the Quickstart and have a database connection configured.
1. Create the Migrations
create_users_table
create_posts_table
create_comments_table
2. Create the Models
models/User.js
models/Post.js
models/Comment.js
3. Build the API Routes
Here’s a complete Express.js blog API using these models:List Posts (paginated)
Get a Single Post with Comments
Create a Post
Publish a Post
Delete a Post (soft delete)
Restore a Deleted Post
Add a Comment
4. Factories for Testing
What’s Next
- Add global scopes to automatically filter posts by the current user
- Use observers to generate slugs automatically on create
- Add casting to serialize
published_atas a formatted date
