Skip to main content

Getting Started

This guide will walk you through creating your first "Hello World" route and controller in the framework.

Prerequisites​

  • WordPress installed and running.
  • The framework plugin customized and active.
  • WP-CLI installed (optional, but recommended for generators).

Step 1: Create a Controller​

You can manually create a file backend/App/Http/Controllers/HelloController.php or use the CLI:

wp droip make:controller HelloController

Edit the file to add a method:

<?php

namespace Ecommerce\App\Http\Controllers;

use Ecommerce\Http\Request;

class HelloController
{
public function index(Request $request)
{
return [
'message' => 'Hello World!',
'timestamp' => time()
];
}
}

Step 2: Define a Route​

Open routes/api.php and add a new route definition that points to your controller.

use Ecommerce\Core\Route;
use Ecommerce\App\Http\Controllers\HelloController;

Route::get('/hello', [HelloController::class, 'index']);

Step 3: Test​

Now, access your WordPress site's REST API endpoint. Assuming your API namespace is configured (e.g., droip/v1), the URL might look like:

https://your-site.com/wp-json/droip/v1/hello

You should see the JSON response:

{
"message": "Hello World!",
"timestamp": 1715693421
}