Step 3 — Your first service

You add the first DeskFlow feature: list tasks for Northwind Studio.

What you will learn

  • Scaffold TaskService with the CLI
  • Map listAction"action": "list"
  • Register the task alias on MainSwitch
Before you start

Generate TaskService

php pionia make:service task

Choose Basic. Edit services/TaskService.php:

<?php

namespace Application\Services;

use Pionia\Collections\Arrayable;
use Pionia\Http\Response\ApiResponse;
use Pionia\Http\Services\Service;

class TaskService extends Service
{
    protected function listAction(Arrayable $data): ApiResponse
    {
        return response(0, 'OK', [
            'tasks' => [
                [
                    'id' => 1,
                    'title' => 'Review homepage mockups',
                    'status' => 'open',
                    'assignee' => 'alex@northwind.studio',
                ],
            ],
        ]);
    }
}

Register on MainSwitch

switches/MainSwitch.php:

return arr([
    'welcome' => WelcomeService::class,
    'task' => TaskService::class,
]);

Try it

Try it yourself
curl -s -X POST http://127.0.0.1:8000/api/v1/ \
  -H "Content-Type: application/json" \
  -d '{"service":"task","action":"list"}'

Hardcoded data is intentional — Step 6 moves this to SQLite.

Common mistakes

  • service not found — typo in alias 'task' or missing use TaskService.
  • Wrong action name — method is listAction, JSON uses "list".