API Explorer
Atom's API Explorer reads the routes registered in your application and presents them in a browser. Select an endpoint to see its HTTP method, path, handler, and declared request fields. This guide uses the ArticleController already registered in the Routing chapter.
Mount the explorer
Add the module in your application's existing modules() hook. The mount path controls where the explorer itself is served.
use Atom\Module\ModuleRegistry;
use Atom\Modules\ApiExplorer\ApiExplorer;
protected function modules(ModuleRegistry $modules): void
{
$modules->add(ApiExplorer::module(), "/atom/api");
}
Open /atom/api in your application. Atom redirects to /atom/api/explorer. The explorer lists routes marked as API routes. For the article example, replace the class-level #[Controller] with #[ApiController] and keep the existing Route::attach(ArticleController::class) call.
use Atom\Router\Attributes\ApiController;
#[ApiController("/api/articles")]
The attribute marks the attached controller routes as API routes without changing their paths. For individually registered routes, call ->api() on the route entry. Use ApiExplorer::module(apiPathPrefix: "/api/articles") when the explorer should list only marked routes under that prefix.
Read a route in the explorer
Select GET /api/articles/{slug}. The explorer identifies ArticleController::show() as the handler. In Request shape, slug is a required string from the route. That comes from the {slug} placeholder and the controller's #[FromRoute] string $slug parameter.
| What you see | Where it comes from |
|---|---|
GET and HEAD on /api/articles/{slug} |
The class prefix and the Get and Head attributes on show(). |
POST /api/articles/preview |
The Post attribute on preview(). |
The required slug field |
The route placeholder and typed handler parameter. |
Request Fields
The explorer describes inputs declared in the handler signature. When a handler reads $request->post()->string("title") inside its body, declare a DTO with a writable property if you want Atom to bind and describe that field.
<?php
namespace App\Requests;
use Atom\Hydrator\Attributes\Dto;
use Atom\Hydrator\Attributes\FromBody;
#[Dto]
final class ArticlePreviewInput
{
#[FromBody]
public string $title;
}
Import App\Requests\ArticlePreviewInput in ArticleController and use it as the preview parameter:
#[Post("preview")]
public function preview(ArticlePreviewInput $input): array
{
return ["title" => $input->title];
}
The preview endpoint now shows title as a required string from the request body. For typed inputs from other sources or for validation rules on a DTO, see Hydration and Validation.