Skip to main content
Make sure you’ve installed Aeros before starting this tutorial.
This quickstart guide will walk you through building a simple web application with Aeros. You’ll learn the basics of routing, controllers, and responses.

Hello World

Let’s start with the simplest possible route. Create a file called routes.php in your application’s root directory:
routes.php
<?php

use Aeros\Src\Classes\Router;

Router::get('/', function() {
    return 'Hello, World!';
});
Start the development server:
php aeros run:app
Visit http://localhost:8000 in your browser to see your “Hello, World!” message.
The Router class supports all standard HTTP methods: get(), post(), put(), patch(), and delete().

Route Parameters

Routes can capture dynamic segments from the URL. Aeros supports two syntaxes for route parameters:
routes.php
Router::get('/user/{id}', function($id) {
    return "User ID: $id";
});

// Alternative syntax
Router::get('/post/:slug', function($slug) {
    return "Post slug: $slug";
});
Parameters are automatically passed to your handler function in the order they appear in the route.

Creating a Controller

1

Generate a controller

Use the CLI to create a new controller:
php aeros make:controller UserController
This creates a new file at app/controllers/UserController.php.
2

Define controller methods

Open the generated controller and add methods:
app/controllers/UserController.php
<?php

namespace App\Controllers;

use Aeros\Src\Classes\Controller;

class UserController extends Controller
{
    public function index()
    {
        return response()->type([
            'users' => [
                ['id' => 1, 'name' => 'John Doe'],
                ['id' => 2, 'name' => 'Jane Smith']
            ]
        ], 200, 'json');
    }

    public function show($id)
    {
        return response()->type([
            'user' => [
                'id' => $id,
                'name' => 'John Doe',
                'email' => '[email protected]'
            ]
        ], 200, 'json');
    }
}
3

Route to the controller

Update your routes to use the controller:
routes.php
Router::get('/users', 'UserController@index');
Router::get('/user/{id}', 'UserController@show');
The Controller@method syntax tells Aeros which controller and method to call.

JSON API Response

Aeros makes it easy to build JSON APIs. The response()->type() method handles content types automatically:
routes.php
Router::get('/api/status', function() {
    return response()->type([
        'status' => 'ok',
        'timestamp' => time(),
        'version' => '1.0.0'
    ], 200, 'json');
});
The second parameter is the HTTP status code, and the third is the content type (defaults to JSON).

Working with Views

To render HTML views, use the view() helper function:
routes.php
Router::get('/welcome', function() {
    return view('welcome', [
        'title' => 'Welcome to Aeros',
        'message' => 'The lighter MVC framework'
    ]);
});
Create a view file at resources/views/welcome.php:
resources/views/welcome.php
<!DOCTYPE html>
<html>
<head>
    <title><?= $title ?></title>
</head>
<body>
    <h1><?= $message ?></h1>
    <p>You're ready to start building with Aeros!</p>
</body>
</html>

Route Groups and Middleware

Group related routes together and apply middleware:
routes.php
Router::group(['middleware' => ['auth']], function() {
    Router::get('/dashboard', 'DashboardController@index');
    Router::get('/profile', 'ProfileController@show');
    Router::post('/profile', 'ProfileController@update');
});

Accessing Request Data

Use the request() helper to access request data:
routes.php
Router::post('/contact', function() {
    $name = request()->getPayload('name');
    $email = request()->getPayload('email');
    $message = request()->getPayload('message');

    // Process the contact form...

    return response()->type([
        'success' => true,
        'message' => 'Thank you for your message!'
    ], 200, 'json');
});

Building a Simple Task List

Let’s put it all together with a simple task list API:
1

Create the controller

php aeros make:controller TaskController
2

Implement CRUD operations

app/controllers/TaskController.php
<?php

namespace App\Controllers;

use Aeros\Src\Classes\Controller;

class TaskController extends Controller
{
    private $tasks = [
        ['id' => 1, 'title' => 'Learn Aeros', 'completed' => false],
        ['id' => 2, 'title' => 'Build an app', 'completed' => false],
    ];

    public function index()
    {
        return response()->type(['tasks' => $this->tasks], 200, 'json');
    }

    public function store()
    {
        $title = request()->getPayload('title');
        
        $newTask = [
            'id' => count($this->tasks) + 1,
            'title' => $title,
            'completed' => false
        ];

        return response()->type([
            'task' => $newTask,
            'message' => 'Task created successfully'
        ], 201, 'json');
    }

    public function update($id)
    {
        $completed = request()->getPayload('completed');

        return response()->type([
            'task' => [
                'id' => $id,
                'completed' => $completed
            ],
            'message' => 'Task updated successfully'
        ], 200, 'json');
    }

    public function destroy($id)
    {
        return response()->type([
            'message' => 'Task deleted successfully'
        ], 200, 'json');
    }
}
3

Define the routes

routes.php
// Task list API
Router::get('/tasks', 'TaskController@index');
Router::post('/tasks', 'TaskController@store');
Router::put('/tasks/{id}', 'TaskController@update');
Router::delete('/tasks/{id}', 'TaskController@destroy');

Next Steps

Learn about routing

Explore advanced routing features like middleware and groups

Work with databases

Connect to databases and use the built-in ORM

API reference

Explore the complete API documentation

CLI commands

Discover all available CLI commands

Build docs developers (and LLMs) love