Skip to main content

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

Already know your schema? Run npx ilana make:model User --migration (and repeat for Post and Comment) to scaffold both the model and migration at once, then skip straight to Step 2.
create_users_table
create_posts_table
create_comments_table
Run the migrations:

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

Seed your database for development:

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_at as a formatted date