Overview
This tutorial walks you through creating the simplest possible Motia application: a “Hello World” API that accepts HTTP requests and processes them in the background. What you’ll learn:- Creating HTTP-triggered Steps
- Enqueuing background jobs
- Using queue-triggered Steps
- Working with state storage
- Structured logging
Prerequisites
Before starting, make sure you have:
- Node.js version 19 or higher
- Bun installed (or npm/pnpm)
Project Setup
Building the Application
Step 1: Create the HTTP API Step
Createsteps/hello-api.step.ts:
steps/hello-api.step.ts
- Triggers: The
httptrigger defines a GET endpoint at/hello - Response schema: Zod schema validates the response structure
- Enqueues: Declares this Step can enqueue messages to the
process-greetingtopic - Flows: Groups related Steps together for organization
Step 2: Create the Background Processing Step
Createsteps/process-greeting.step.ts:
steps/process-greeting.step.ts
- Queue trigger: Listens to the
process-greetingtopic - Input validation: Zod schema validates incoming queue messages
- State storage: Persists data using
state.set(bucket, key, value) - Structured logging: Includes contextual data with log messages
Running the Application
Customization
Add Environment Variables
Create a.env file:
Retrieve Stored Greetings
Add a new Step to retrieve greetings from state:steps/get-greeting.step.ts
Next Steps
Now that you’ve built your first Motia application, explore more advanced features:Todo API
Build a full CRUD API with validation
Message Queue
Learn pub/sub patterns and streams
Scheduled Tasks
Run jobs on a schedule with cron
API Reference
Explore the full Motia API