1. Go to this page and download the library: Download zolta/http library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zolta / http example snippets
#[Route(path: 'users/{id}', methods: ['GET'], auth: 'sanctum', authorized: ['can_manage_users'])]
#[Request(GetUserByIdRequest::class, GetUserByIdDTO::class)]
#[Service(GetUserByIdService::class, 'User found.', 200)]
#[Response(UserResource::class)]
#[Doc(summary: 'Get a user by ID')]
public function show() {} // That's it. The entire endpoint.
use Zolta\Http\Controller\Controller;
use Zolta\Http\Router\Attributes\Route;
use Zolta\Http\Request\Attributes\Request;
use Zolta\Http\Service\Attributes\Service;
use Zolta\Http\Response\Attributes\Response;
use Zolta\Http\Service\Attributes\Doc;
final class UserController extends Controller
{
#[Route(path: 'users/{id}', methods: ['GET'], auth: 'sanctum', authorized: ['can_manage_users'])]
#[Request(GetUserByIdRequest::class, GetUserByIdDTO::class)]
#[Service(GetUserByIdService::class, 'User found.', 200)]
#[Response(UserResource::class)]
#[Doc(summary: 'Get a user by ID')]
public function show() {}
}
use Zolta\Http\Request\BaseRequest;
final class GetUserByIdRequest extends BaseRequest
{
public function rules(): array
{
return ['id' => '
public function trustedData(): array
{
return ['user_id' => (string) $this->user()->getAuthIdentifier()];
}
use Zolta\Support\Application\DTO\Input\InputDTO;
use Zolta\Support\Application\Attributes\FromRequest;
class GetUserByIdDTO extends InputDTO
{
final public function __construct(
#[FromRequest('id')]
public readonly string $id,
public readonly array $options = []
) {}
}
use Zolta\Http\Response\Resources\Resource;
final class UserResource extends Resource
{
public function toArray(): array
{
return [
'user' => $this->all()['user'],
];
}
}