[WIP] feat(api): add API "builder"
[!WARNING] This is VERY MUCH a Working in Progress.
Discord discussion here.
This is just to show-case an idea/PoC for a an API Development solution for Tempest.
Here's how I envision a developer would use such a feature:
Sample File structure
Just like the rest of Tempest, the file structure DOES NOT matter - however, just for the sake of having an example, here it is.
.
└── app/
├── ApiResources/
│ └── UserResource.php
└── Models/
├── Post.php
└── User.php
Using in a dedicated resource class
Here's how a UserResource class could look like.
#[ResourceRecord(User::class)]
final class UserResource
{
use IsApiResource;
}
Using directly in a model (🤮)
final class Post
{
use IsApiResource;
public Id $id;
public string $title;
//...
}
Using Only certain CRUD endpoints
#[ResourceRecord(User::class)]
final class UserResource
{
use HasApiIndexEndpoint;
use HasApiShowEndpoint;
}
Overwriting defaults
In any class that uses IsApiResource, defaults can be overwritten:
#[ResourceRecord(User::class)]
final class UserResource
{
use IsApiResource;
public static function getResourceApiVersion(): ?string
{
return 'v2';
}
public static function getResourcePagination(): ?Pagination
{
return new OffsetPagination();
}
public static function getResourceSearchableColumns(): ?array
{
return ['name', 'email'];
}
public static function getResourceMiddlewares(): array
{
return [
LogRequestMiddleware::class,
];
}
}
Here is the related issue #928
This pull request is stale because it has been open for 30 days with no activity.
This pull request was closed because it has been inactive for 1 day since being marked as stale.